You are on page 1of 5

Struts to portlet

Struts to portlet 2009

Content
1.1

Preparation .................................................................................................................................... 3

1.2

portlet.xml ..................................................................................................................................... 3

1.3

web.xml ......................................................................................................................................... 4

1.4

struts-portlet-config.xml ............................................................................................................... 4

1.5

struts-config.xml ........................................................................................................................... 4

1.6

Pages ............................................................................................................................................. 4

1.7

liferay-portlet.xml ......................................................................................................................... 5

1.8

liferay-display.xml ........................................................................................................................ 5

2/5

Struts to portlet 2009

1.1 Preparation
Download at http://portals.apache.org/bridges/download.html
Unzip it, in folder jars (or other folder), you need these jars to convert Strust to portlet.

portals-bridges-frameworks
portals-bridges-struts
portals-bridges-common

Copy to WEB-INF/lib of Struts project.

1.2 portlet.xml
Create a file XML called portlet.xml, placed in folder WEB-INF.
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" Name to display of
version="1.0">
portlet
<portlet>
<portlet-name>define_your_portlet_name_here</portlet-name>
<display-name>define_your_portlet_display_name_here </display-name>
<description>This is a Struts Test Portlet</description>
<portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>
<init-param>
It must be like this.
<name>ServletContextProvider</name>
<!-- The following portal implementation has been configured manually -->
<value>com.liferay.util.bridges.struts.LiferayServletContextProviderWrapper</value>
</init-param>
<init-param>
This line is depends on portal. In this
<name>ViewPage</name>
material, I deploy to Liferay Portal.
<value>/pages/index.jsp</value>
</init-param>
<init-param>
<name>EditPage</name>
<value>/pages/help.jsp </value>
</init-param>
<expiration-cache>-1</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>EDIT</portlet-mode>
</supports>
<portlet-info>
<title>Enter_your_portlet_title_here</title>
<short-title>Struts</short-title>
<keywords>Struts, validator</keywords>
</portlet-info>
</portlet>
</portlet-app>

3/5

Struts to portlet 2009

1.3 web.xml
Edit file web.xml
Before editing
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

Change org.apache.struts.action.ActionServlet to org.apache.portals.bridges.struts.PortletServlet


<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.portals.bridges.struts.PortletServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

1.4 struts-portlet-config.xml
Create a file named struts-portel-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<portlet-url-type>
<action path="/greeting"/> <!all actions defined in struts-config.xml-->
</portlet-url-type>
</config>

1.5 struts-config.xml
Edit file struts-config.xml
Add this line in file struts-config.xml
<controller pagePattern=$M$P inputForward=false
processorClass=org.apache.portals.bridges.struts.PortletRequestProcessor/>

1.6 Pages
Change all Struts HTML taglib to Bridge HTML taglib
<%@ taglib uri=/ WEB-INF/struts-portlet-html.tld prefix=html %>

to
<%@ taglib uri=http://portals.apache.org/bridges/struts/tags-portlet-html prefix=html %>

4/5

Struts to portlet 2009

Remove all tag like <html>, <title>, <body>.., just remain the content in the <body>
To deploy to Liferay portal, we need to create 2 more files: liferay-portlet.xml and liferay-display.xml

1.7 liferay-portlet.xml
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application
4.4.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_4_4_0.dtd">
<liferay-portlet-app>
<portlet>
<portlet-name>portlet_name</portlet-name>
<portlet-url-class>
com.liferay.portal.apache.bridges.struts.LiferayStrutsPortletURLImpl
</portlet-url-class>
<use-default-template>true</use-default-template>
<restore-current-view>true</restore-current-view>
</portlet>
</liferay-portlet-app>

1.8 liferay-display.xml
<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 4.0.0//EN"
"http://www.liferay.com/dtd/liferay-display_4_0_0.dtd">
<display>
<category name="category_name">
<portlet id="portlet_name" />
</category>
</display>

***********

5/5

You might also like