
Struts Action Portlet in Plugin SDK
Create Struts Action Portlet in Plugin Enviroinment
[Important note: it's not recommended by Liferay to use its StrutsPortlet bridge in plugins. We recommend using a custom framework for simple portlets or one of the modern frameworks with portlet support for more advanced portlets such as JSF (for example with IceFaces), Struts 2 or Spring MVC]
Step 1.
Go to Command Prompt inside Plugin: Plugin>Portlets>
Execute the create.bat file with your portlet name as follows:
project\plugin\portlets>create.bat sample-struts-plugin "Sample Struts Plugin Portlet"
Step 2:
Folder with name sample-struts-plugin-portlet will be created in ur portlets folder. Verify it.
Go to ur portlet folder and edit the liferay-portlet.xml file by adding the following after <icon/>
\portlets\sample-struts-plugin-portlet\docroot\WEB-INF\liferay-portlet.xml
<struts-path>sample/struts/plugin</struts-path>
Step 3:
Go to ur portlet folder and edit the portlet.xml file by changing the following tags..
(\portlets\sample-struts-plugin-portlet\docroot\WEB-INF\portlet.xml)
Replace ,
<portlet-class>com.sample.jsp.portlet.JSPPortlet</portlet-class>
with
<portlet-class>com.liferay.portlet.StrutsPortlet</portlet-class>
---------------------------------
And replace,
<init-param>
<name>view-jsp</name>
<value>/view.jsp</value>
</init-param>
with
<init-param>
<name>view-action</name>
<value>/sample/struts/plugin/view</value>
</init-param>
---------------------------------
and ADD,
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
Step 4:
Go to ur WEB-INF folder & create struts-config.xml like this
( \portlets\sample-struts-plugin-portlet\docroot\WEB-INF\struts-config.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<action-mappings>
<action path="/sample/struts/plugin/view" type="com.xyz.action.SampleStrutsAction" >
<forward name="portlet.sample.struts.view" path="portlet.sample.struts.view" />
</action>
</action-mappings>
<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"></controller>
<message-resources parameter="content.test.Language"></message-resources>
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"></set-property>
<set-property property="moduleAware" value="true"></set-property>
<set-property property="definitions-parser-validate" value="true"></set-property>
</plug-in>
</struts-config>
Step 5:
Go to ur WEB-INF folder & create tiles-defs.xml like this
(\portlets\sample-struts-plugin-portlet\docroot\WEB-INF\tiles-defs.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
<tiles-definitions>
<!-- Sample Struts Plugin -->
<definition name="portlet.sample.struts.view" path="/struts/jsp/view.jsp"></definition>
</tiles-definitions>
Step 6:
Goto ur WEB-INF\src\com\xyz\action\ folder & create SampleStrutsAction.java insie:
(\portlets\sample-struts-plugin-portlet\docroot\WEB-INF\src\com\xyz\action\ )
package com.xyz.action;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.liferay.portal.struts.PortletAction;
public class SampleStrutsAction extends PortletAction{
public ActionForward render(ActionMapping mapping, ActionForm form,
PortletConfig portletConfig, RenderRequest renderRequest,
RenderResponse renderResponse) throws Exception {
System.out.println("SampleStrutsAction render()..");
return mapping.findForward("portlet.sample.struts.view");
}
}
Step 7:
Goto ur WEB-INF folder & edit web.xml :
( \portlets\sample-struts-plugin-portlet\docroot\WEB-INF\web.xml )
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<listener>
<listener-class>com.liferay.portal.kernel.spring.context.PortletContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>PortletActionServlet</servlet-name>
<servlet-class>com.liferay.portal.struts.PortletActionServlet</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>
<servlet-mapping>
<servlet-name>PortletActionServlet</servlet-name>
<url-pattern>/portlet_action/*</url-pattern>
</servlet-mapping>
</web-app>
Step 8:
Go to ur docroot folder & create META-INF\context.xml like this
(\portlets\sample-struts-plugin-portlet\docroot\META-INF\context.xml )
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Loader
loaderClass="com.liferay.support.tomcat.loader.PortalClassLoader"
/>
</Context>
Step 9:
create view.jsp file inside :
(\sample-struts-plugin-portlet\docroot\html\struts\jsp\view.jsp)
File Structure Tree View for Plugin Portlet:
- Gnaniyar Zubair
rasikow@gmail.com