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:

 

Tree View of Struts Action Portlet in SDK

 

 

 

- Gnaniyar Zubair

  rasikow@gmail.com

 

 

 

0 Attachments
46020 Views
Average (1 Vote)
The average rating is 4.0 stars out of 5.
Comments
Threaded Replies Author Date
Hi Gnaniyar, Thanks for your contribution. ... Jorge Ferrer September 17, 2009 9:39 AM
I followed this tutorial but using "JOnAS... Paolo Bianchi September 21, 2009 2:59 AM
Hi Jorge, I have a strange question: why does... Péter Pluhár December 1, 2010 2:55 AM
hi i need to know how can i integrate a portlet... fatima nadir April 27, 2011 6:45 AM
This obviously doesn't work. How can you leave... tom aronsons May 26, 2011 1:31 PM
Hi Zubair, There is a serious point to... Muhammed Shakir December 27, 2009 11:46 PM
pls help me out, I am using liferay plugin SDK... Sudhakar T July 22, 2010 6:41 AM
sudhakar, you must download ant and add to the... carlos alberto July 27, 2010 4:55 AM
Hi, I am using liferay plugin SDK 6.0. When i... Sai Pradeep Dandem August 6, 2010 3:50 AM
Hi sai, I think you have to download the jar... radmadsad sadada August 23, 2010 11:53 AM
I'm trying to locate some documentation on... Philip T August 6, 2010 7:28 AM
It would be really great if I could get a... radmadsad sadada August 23, 2010 11:51 AM
Hi Zubair can you give the jar files for this... Manikandan S September 29, 2010 6:21 AM
Hi zubair, I am getting error while I am... Manikandan S September 29, 2010 9:10 PM
Hi, I solved the problem of Portlet with... Boymix81 Nick October 21, 2010 12:23 AM

Hi Gnaniyar,

Thanks for your contribution.

For reference, though, note that 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.
Posted on 9/17/09 9:39 AM.
I followed this tutorial but using "JOnAS tomcat" i get the following error:
WebappLoader.start : LifecycleException
java.lang.ClassNotFoundException: com.liferay.support.tomcat.loader.PortalClassLoader
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

How can i solve my problem? Thx.
Posted on 9/21/09 2:59 AM in reply to Jorge Ferrer.
Hi Zubair,
There is a serious point to consider when using any artifact from portal-impl.jar (PortletAction is from portal-impl.jar) and that is: If tomorrow liferay decides to shift from Struts 1.x to 2.x in the new version, the classes in portal-impl.jar file will change and you will have to make lot of changes in your plugin project in order to make your portlets work on new version of liferay.
Plugin projects are created so that they are agnostic of underlying architecture of liferay and can be easily ported to new versions of liferay. Plugin projects are supposed to use the liferay services (portal-services.jar) and liferay kernel at the most (portal-kernel.jar) and nothing more.
You are also violating important principle of OO Design i.e. "do not skip layers unless you have a very good reason". Portal Service and Portal Kernel depends upon Portal impl. You use portal impl only in case you want to extend the existed services in the extension environment
Please feel free to correct me if I am wrong.
Posted on 12/27/09 11:46 PM.
pls help me out,
I am using liferay plugin SDK 6 when am trying the first step am getting following issue in command prompt, anyone suggest me about this please.

D:\SUDHAKAR\BLM\LIFERAY\LIFERAY SDK PLUGIN\liferay-plugins-sdk-6.0.2\portlets>create.bat TEMS-struts-plugin "TEMSPortlet-portlet"
'ant' is not recognized as an internal or external command,
operable program or batch file.
Posted on 7/22/10 6:41 AM.
sudhakar, you must download ant and add to the classpath
Posted on 7/27/10 4:55 AM in reply to Sudhakar T.
Hi, I am using liferay plugin SDK 6.0. When i am adding the StrutsPortlet class in the <portlet-class> node in portlet.xml file, it is showing error that
"The portlet class com.liferay.portlet.StrutsPortlet was not found on the Java Build Path"

Please help me how to create a struts based portlet in 6.0 version.
Posted on 8/6/10 3:50 AM.
I'm trying to locate some documentation on defining action events in the 6.0 portlet plugin environment. Any advice?
Posted on 8/6/10 7:28 AM.
It would be really great if I could get a proper tutorial which explains how to create a struts application in plugin sdk. I'm new to liferay and have no clue of what I'm doing.

Thanks
Rahul
Posted on 8/23/10 11:51 AM.
Hi sai,
I think you have to download the jar file for the strutsportlet class.
I couldn't find the jar file myself to download yet.
Posted on 8/23/10 11:53 AM in reply to Sai Pradeep Dandem.
Hi Zubair can you give the jar files for this struts portlet or give the download link
Posted on 9/29/10 6:21 AM.
Hi zubair,

I am getting error while I am trying to use your Struts Action Portlet in Plugin SDK "java.lang.ClassNotFoundException: com.liferay.util.bean.PortletBeanLocatorUtil" Could you please tell me how to clear this?
Posted on 9/29/10 9:10 PM.
Hi,

I solved the problem of Portlet with Struts that work in Liferay 5.2.3 and don't work in Liferay 6.0.x, for me the solution was state to porting the portlet to use struts 2 .

This is my library configuration :

in WEB-INF/lib
- dwr-1.1.1.jar
- ognl-3.0.jar
- struts2-core-2.2.1.jar
- struts2-portlet-plugin-2.2.1.jar
- struts2-tiles-plugin-2.2.1.jar
- xwork-core-2.2.1.jar

dependency package:

portal-dependency-jars=\
commons-fileupload.jar,\
commons-logging.jar,\
freemarker.jar,\
jstl-api.jar,\
jstl-impl.jar,\
commons-io.jar,\
commons-beanutils.jar,\
commons-collections.jar,\
commons-digester.jar,\
commons-lang.jar,\
commons-validator.jar,\
javassist.jar

I following this tutorial :

- Traslate configurations file from struts1 to struts2 ( differents )
http://www.infoq.com/articles/converting-struts-2-part1
http://www.infoq.com/art­icles/migrating-struts-2-part2

- Struts2 in portlet
http://www.robisoft.com/downloads/
https://cwiki.apache.org/confluence/dis­play/WW/Struts+2+Portlet+Tutorial

- Using tiles-plugin of Struts2
http://www.vaannila.com/struts-2/struts-2-example/struts-2-tiles-example-­1.html

- Post Liferay used :
http://www.liferay.com/community/forums/-/message_boards/message/378595
http://w­ww.liferay.com/community/forums/-/message_boards/message/4504092;jsessionid=DEC9­9482793206596459AA1600585E9F.node-1
http://www.liferay.com/community/forums/-/mes­sage_boards/message/4555589;jsessionid=ED7F86A20913821932189CDDADD33951.node-1
ht­tp://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Struts+Action+Portlet+­in+Plugin+SDK

I hope it's usefull .

Best Regards
Posted on 10/21/10 12:23 AM in reply to Manikandan S.
Hi Jorge,

I have a strange question: why does all example plugin portlet code use struts? It just can't work, since liferay struts classes are in portal-impl.jar. Or do I miss something?
Posted on 12/1/10 2:55 AM in reply to Jorge Ferrer.
hi i need to know how can i integrate a portlet in liferay portal
Posted on 4/27/11 6:45 AM in reply to Péter Pluhár.
This obviously doesn't work. How can you leave so many steps out? Why not just post up a zip file of your portlet.
Posted on 5/26/11 1:31 PM in reply to fatima nadir.