Monday 16 November 2009

Create a Struts Portlet using Liferay Plugin Sdk

There is an article available at Liferay Wiki to help you develop a Struts Based Portlet using there Plugin SDK, but chances are pretty high that the article alone wont suffice.

Here are a few problems you might face when you develop a Struts based Portlet.

1. You might get errors for ActionForward, ActionMapping and so on.
2. Your project will have compilation problems.

Here are a few simple steps to create a Struts Based portlet:


1. Download plugin-sdk from http://sourceforge.net/projects/lportal/files/
2. Create a new project in your eclipse using this plugin.
3. Modify the build.properties. Make another copy of the same as build..properties and place it at same location.
4. Change the file to give your tomcat location. Also tell the deploy folder location where it will dump war file.
5. Before you create a new Struts Portlet, check for your ant. Go to command prompt and type ant. If it gives some message you are fine. Else you need to set ANT_HOME variable like your JAVA_HOME
6.When you create a new Struts Portlet using SDK then you must create and action class which extends StrutsAction and implements its methods like doView().

Like for example:

public class SampleStrutsAction extends StrutsPortlet {

public void doView(RenderRequest req, RenderResponse res)
throws IOException, PortletException {

super.doView(req, res);
}


7. After creating this class you need to refer it in the portlet.xml file:
Create an entry like:

com.xyz.struts.portlet.SampleStrutsAction

8. Now you are ready to create an action class having the render() and processAction() methods.

9. You may need to do one more thing, that is attaching the Liferay Portal Source Code if you want to add more functionality to your Portlet.

A sample struts portlet can be found here. Just deploy it to see that it works fine. Then import it to view the structure.

One more thing, attach portlet.jar, portal-kernel.jar and struts.jar to your plugin sdk.

Compile your portlet and then deploy.

No comments:

Post a Comment