Tuesday, June 15, 2010

Struts Action Portlet in Plugin SDK

Create Struts Action Portlet in Plugin Enviroinment

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

\portlets\sample-struts-plugin-portlet\docroot\WEB-INF\liferay-portlet.xml

sample/struts/plugin

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 ,

com.sample.jsp.portlet.JSPPortlet

with

com.liferay.portlet.StrutsPortlet

---------------------------------

And replace,

view-jsp

/view.jsp

with

view-action

/sample/struts/plugin/view

---------------------------------

and ADD,

text/html

view

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)

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)

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 )

com.liferay.portal.kernel.spring.context.PortletContextLoaderListener

PortletActionServlet

com.liferay.portal.struts.PortletActionServlet

config

/WEB-INF/struts-config.xml

1

PortletActionServlet

/portlet_action/*

Step 8:

Go to ur docroot folder & create META-INF\context.xml like this

(\portlets\sample-struts-plugin-portlet\docroot\META-INF\context.xml )

loaderClass="com.liferay.support.tomcat.loader.PortalClassLoader"

/>

Step 9:

create view.jsp file inside :

(\sample-struts-plugin-portlet\docroot\html\struts\jsp\view.jsp)

File Structure Tree View for Plugin Portlet:

Tree View of Struts Action Portlet  in SDK


Ref: http://www.liferay.com/community/wiki/-/wiki/Main/Struts+Action+Portlet+in+Plugin+SDK