Forums

Home » Liferay Portal » English » x. Miscellaneous

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
mukund S
Struts Portlet
October 25, 2012 2:30 AM
Answer

mukund S

Rank: Junior Member

Posts: 26

Join Date: October 25, 2012

Recent Posts

Hi All,
I need to know how to create STRUTS PORTLET in liferay....... Could anyone help me to know how it can be done and Please explain every steps from starting
Gautam Sharma
RE: Struts Portlet
October 26, 2012 8:54 AM
Answer

Gautam Sharma

Rank: Junior Member

Posts: 61

Join Date: April 30, 2012

Recent Posts

Hi Mukund

Please go through below link

http://www.liferay.com/community/wiki/-/wiki/Main/Tutorial+-+Struts+Portlet+War+-+Overview

thanks
mukund S
RE: Struts Portlet
October 27, 2012 12:39 AM
Answer

mukund S

Rank: Junior Member

Posts: 26

Join Date: October 25, 2012

Recent Posts

Hi
Thanks for your reply......but I need to know the steps from the beginning.......Whether I need t o select the portlet or ext while creating a new liferay project.....I am using liferay 6.0
mukund S
RE: Struts Portlet
October 27, 2012 4:34 AM
Answer

mukund S

Rank: Junior Member

Posts: 26

Join Date: October 25, 2012

Recent Posts

hi,
could you tell me how to do portlet preferences ?
Muthukumar Thangavinayagam
RE: Struts Portlet
October 28, 2012 2:48 AM
Answer

Muthukumar Thangavinayagam

Rank: New Member

Posts: 21

Join Date: December 16, 2010

Recent Posts

Hi Mukund,

Please find attached sample struts portlet . and follow steps to create Struts Portlet in Liferay 6.x

Liferay 6 HelloWorld Struts Portlet

1.1. liferay-portlet.xml

Update the below content

<portlet>
<portlet-name>emptoris-search</portlet-name>
<portlet-url-class>com.liferay.portal.apache.bridges.struts.LiferayStrutsPortletURLImpl</portlet-url-class>
<use-default-template>true</use-default-template>
</portlet>

2. portlet.xml

Update portlet-class and init-param

<portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>
<init-param>
<name>ServletContextProvider</name>
<value>com.liferay.util.bridges.struts.LiferayServletContextProviderWrapper</value>
</init-param>
<init-param>
<name>ViewPage</name>
<value>/portlet_action/search/view</value>
</init-param>

<portlet>
<portlet-name>emptoris-search</portlet-name>
<display-name>Emptoris-Search</display-name>
<portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>
<init-param>
<name>ServletContextProvider</name>
<value>com.liferay.util.bridges.struts.LiferayServletContextProviderWrapper</value>
</init-param>
<init-param>
<name>ViewPage</name>
<value>/portlet_action/search/view</value>
</init-param>

3.web.xml

insert struts servlet class

<servlet>
<servlet-name>PortletActionServlet</servlet-name>
<servlet-class>com.liferay.util.bridges.struts.LiferayPortletServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>PortletActionServlet</servlet-name>
<url-pattern>/portlet_action/*</url-pattern>
</servlet-mapping>

<taglib>
<taglib-uri>http://struts.apache.org/tags-bean</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://portals.apache.org/bridges/struts/tags-portlet-html</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-portlet-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://struts.apache.org/tags-logic</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://struts.apache.org/tags-nested</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://struts.apache.org/tags-tiles</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>

4.struts-config.xml

<action path="/search/view" type="com.cignex.sample.struts.StrutsHelloWorldAction" scope="request" validate="false">
<forward name="view_result" path="portlet.sample.view"></forward>
</action>

5.tiles-defs.xml

<definition name="portlet.sample.view" extends="portlet.search">
<put name="portlet_content" value="/portlet/sample/viewResult.jsp" />
</definition>

6.StrutsHelloWorldAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub

return mapping.findForward("view_result");
}


Best Regards,
Muthukumar Thangavinayagam
Attachments: StrutsHelloWorld-portlet.rar (2,323.1k)
Muthukumar Thangavinayagam
RE: Struts Portlet
October 28, 2012 2:51 AM
Answer

Muthukumar Thangavinayagam

Rank: New Member

Posts: 21

Join Date: December 16, 2010

Recent Posts

mukund S:
hi,
could you tell me how to do portlet preferences ?



Please check code snippet,

<liferay-portlet:actionURL portletConfiguration="true" var="configurationActionURL" />

<form action="<%= configurationActionURL %>" method="post" name="fm">
<input name="<%= Constants.CMD %>" type="hidden" value="<%= Constants.UPDATE %>" />

<fieldset class="block-labels">
<legend><liferay-ui:message key="Configuration for Facebook" /></legend>

<aui:input label="FaceBook Id" name="faceBookName" type="text" value="<%= faceBookName %>" />
<aui:input label="No of Walls" name="numberWall" type="text" value="<%= numberWall %>" />
</fieldset>
<br/>
<input name="submit" type="submit" value="Save" />
</form>





PortletPreferences preferences =PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);

String faceBookName = ParamUtil.getString(actionRequest, "faceBookName");
String numberWall = ParamUtil.getString(actionRequest, "numberWall");

String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

if(cmd.equalsIgnoreCase(Constants.UPDATE)){

preferences.setValue("faceBookName", faceBookName);
preferences.setValue("numberWall", numberWall);

if (SessionErrors.isEmpty(actionRequest)) {
preferences.store();

SessionMessages.add(actionRequest, "success");

}


}

Best Regards,
Muthukumar. Thangavinayagam
mukund S
RE: Struts Portlet
October 28, 2012 9:46 PM
Answer

mukund S

Rank: Junior Member

Posts: 26

Join Date: October 25, 2012

Recent Posts

HI,
I am getting error in this line

<portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>

Thanks & Regards
Vishal Panchal
RE: Struts Portlet
October 28, 2012 10:36 PM
Answer

Vishal Panchal

Rank: Expert

Posts: 279

Join Date: May 20, 2012

Recent Posts

mukund S:
HI,
I am getting error in this line

<portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>

Thanks & Regards



Are you getting any error in console..like class not found.org.apache.portals.bridges.struts.StrutsPortlet.?

If yes than visit this link for solution.

Thanks & Regards,
Vishal R. Panchal
Muthukumar Thangavinayagam
RE: Struts Portlet
October 28, 2012 11:42 PM
Answer

Muthukumar Thangavinayagam

Rank: New Member

Posts: 21

Join Date: December 16, 2010

Recent Posts

mukund S:
HI,
I am getting error in this line

<portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>

Thanks & Regards



Hi Mukund ,

Did u added jar files in your custom-portlet lib folder ? please check my previous post, I have attached sample struts portlet code snippet

Thanks,
Muthukumar Thangavinayagam
mukund S
RE: Struts Portlet
October 29, 2012 7:02 AM
Answer

mukund S

Rank: Junior Member

Posts: 26

Join Date: October 25, 2012

Recent Posts

hi,
Thank u.... I got that struts portlet.....
Do u have any basic program on portlet preferences ?
Muthukumar Thangavinayagam
RE: Struts Portlet
October 29, 2012 10:27 PM
Answer

Muthukumar Thangavinayagam

Rank: New Member

Posts: 21

Join Date: December 16, 2010

Recent Posts

mukund S:
hi,
Thank u.... I got that struts portlet.....
Do u have any basic program on portlet preferences ?




Please check my previous post . I have shared preferences code snippet

Thanks,
Muthukumar Thangavinayagam,
mukund S
RE: Struts Portlet
November 1, 2012 11:54 PM
Answer

mukund S

Rank: Junior Member

Posts: 26

Join Date: October 25, 2012

Recent Posts

Hi,
Could you explain the flow of the struts portlet.........
I am getting a little about the flow but I dont know when the action class is executed...?
mukund S
RE: Struts Portlet
November 2, 2012 5:13 AM
Answer

mukund S

Rank: Junior Member

Posts: 26

Join Date: October 25, 2012

Recent Posts

Hi
I am working on sample struts portlet where i have two jsp files and from first jsp, the control is redirected to second jsp.....but i am not getting it.....
The code is as follows :

StrutsHelloWorldAction.java

public class StrutsHelloWorldAction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub

System.out.println("request.getParameter(result) "+request.getParameter("result"));


if(request.getParameter("result")!=null)
{
System.out.println("inside");
String name=request.getParameter("name");
System.out.println(name);
request.setAttribute("Result", name);
return mapping.findForward("final_result");
}
else{
System.out.println("hi hi hi");
return mapping.findForward("view_result");
}
}

}

viewResult.jsp

<div>
Welcome to Liferay Struts Portlet
<form action="<portlet:actionURL>
<portlet:param name="struts_action" value="/hi" />
</portlet:actionURL>">
<input type="text" name="name"/>
<input type="hidden" name="result" value="input"/>
<input type="submit"/>
</form>
</div>



struts-config.xml
<action-mappings>

<action path="/search/view" type="com.cignex.sample.struts.StrutsHelloWorldAction" scope="request" validate="false">
<forward name="view_result" path="portlet.sample.view"></forward>
</action>

<action path="/hi" type="com.cignex.sample.struts.StrutsHelloWorldAction" scope="request" validate="false">
<forward name="final_result" path="/html/portlet/sample/result.jsp"></forward>
</action>

</action-mappings>


result.jsp
<%String name=request.getAttribute("Result").toString(); %>

Welcome name




tiles-defs.xml
<tiles-definitions>

<!-- Sample Struts -->

<definition name="portlet.search" path="/html/portlet/sample/template.jsp"></definition>

<definition name="portlet.sample.view" extends="portlet.search">
<put name="portlet_content" value="/portlet/sample/viewResult.jsp" />
</definition>

<definition name="portlet.sample.result" extends="portlet.search">
<put name="portlet_content" value="/portlet/sample/result.jsp" />
</definition>

</tiles-definitions>





I am not able to redirect from one jsp to another..............