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 附件
48878 查看
平均 (1 投票)
满分为 5,平均得分为 4.0。
评论
讨论主题回复 作者 日期
Hi Gnaniyar, Thanks for your contribution. ... Jorge Ferrer 2009年9月17日 上午9:39
I followed this tutorial but using "JOnAS... Paolo Bianchi 2009年9月21日 上午2:59
Hi Jorge, I have a strange question: why does... Péter Pluhár 2010年12月1日 上午2:55
hi i need to know how can i integrate a portlet... fatima nadir 2011年4月27日 上午6:45
This obviously doesn't work. How can you leave... tom aronsons 2011年5月26日 下午1:31
Hi Zubair, There is a serious point to... Muhammed Shakir 2009年12月27日 下午11:46
pls help me out, I am using liferay plugin SDK... Sudhakar T 2010年7月22日 上午6:41
sudhakar, you must download ant and add to the... carlos alberto 2010年7月27日 上午4:55
Hi, I am using liferay plugin SDK 6.0. When i... Sai Pradeep Dandem 2010年8月6日 上午3:50
Hi sai, I think you have to download the jar... radmadsad sadada 2010年8月23日 上午11:53
I'm trying to locate some documentation on... Philip T 2010年8月6日 上午7:28
It would be really great if I could get a... radmadsad sadada 2010年8月23日 上午11:51
Hi Zubair can you give the jar files for this... Manikandan S 2010年9月29日 上午6:21
Hi zubair, I am getting error while I am... Manikandan S 2010年9月29日 下午9:10
Hi, I solved the problem of Portlet with... Boymix81 Nick 2010年10月21日 上午12:23

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.
在 09-9-17 上午9:39 发帖。
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.
在 09-9-21 上午2:59 发帖以回复 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.
在 09-12-27 下午11:46 发帖。
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.
在 10-7-22 上午6:41 发帖。
sudhakar, you must download ant and add to the classpath
在 10-7-27 上午4:55 发帖以回复 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.
在 10-8-6 上午3:50 发帖。
I'm trying to locate some documentation on defining action events in the 6.0 portlet plugin environment. Any advice?
在 10-8-6 上午7:28 发帖。
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
在 10-8-23 上午11:51 发帖。
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.
在 10-8-23 上午11:53 发帖以回复 Sai Pradeep Dandem
Hi Zubair can you give the jar files for this struts portlet or give the download link
在 10-9-29 上午6:21 发帖。
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?
在 10-9-29 下午9:10 发帖。
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
在 10-10-21 上午12:23 发帖以回复 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?
在 10-12-1 上午2:55 发帖以回复 Jorge Ferrer
hi i need to know how can i integrate a portlet in liferay portal
在 11-4-27 上午6:45 发帖以回复 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.
在 11-5-26 下午1:31 发帖以回复 fatima nadir