Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
ruchi sharma
How to call the struts action (in ext) from a portlet ??
June 12, 2012 8:46 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Hi,
I am trying to call the new struts action defined in ext (struts-config-ext.xml, tiles-defs-ext.xml) from a portlet.
But, unfortunately its not working for me, can anybody tell me with an example how to achieve this.
Thanks
Ruchi
Chintan Akhani
RE: How to call the struts action (in ext) from a portlet ??
June 12, 2012 11:13 PM
Answer

Chintan Akhani

Rank: Regular Member

Posts: 111

Join Date: March 13, 2008

Recent Posts

From which portlet you are calling struts action, whether it is a plugin portlet or ext?
Lalit Jugran
RE: How to call the struts action (in ext) from a portlet ??
June 12, 2012 11:32 PM
Answer

Lalit Jugran

Rank: Junior Member

Posts: 25

Join Date: July 25, 2010

Recent Posts

Hi Ruchi,

If you are talking about struts path in ext environment(like liferay 5.2.3) then following steps may be helpful.

1- make a PortletURL in the jsp of portlet where you want to use this path.

PortletURL submitURL=renderResponse.createActionURL();
submitURL.setParameter("struts_action","/ext/abc/manage_account/manage");
submitURL.setWindowState(WindowState.NORMAL);

2- Make following entry in the struts-config.xml

<action path="/ext/abc/manage_account/manage" type="com.abc.portlet.manage_account.action.ManageAccountAction" >
<forward name="portlet.ext.abc.manage_account.view" path="portlet.ext.abc.manage_account.view" />
</action>

3- Make following entry in tiles-defs.xml
<definition name="portlet.ext.abc.manage_account.view" extends="portlet">
<put name="portlet_content" value="/portlet/manage/view2.jsp" />
</definition>

view2.jsp is the destination jsp, where you will navigate after following this struts path. In liferay 6 there is no scope of extending these files struts-config.xml or tiles-defs.xml

Hope this will help...
Amit Doshi
RE: How to call the struts action (in ext) from a portlet ??
June 12, 2012 11:47 PM
Answer

Amit Doshi

Rank: Liferay Master

Posts: 544

Join Date: December 29, 2010

Recent Posts

Hi Ruchi,

My First Question why you prefer EXT , you can do the same thing in the HOOK also.

And if you try to create the new Struts Action then I prefer you to do in hook or Override the Existing one. Because EXT required to Restart the Server..

Please check below link, how to use the Struts action in HOOK.

http://www.liferay.com/community/forums/-/message_boards/message/14288957
http://www.liferay.com/web/mika.koivisto/blog/-/blogs/7132115

Hope it helps.

Regards,
Amit Doshi
ruchi sharma
RE: How to call the struts action (in ext) from a portlet ??
June 13, 2012 1:22 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

HI Chintan,
It is a plugin portlet.
Thanks
Ruchi
ruchi sharma
RE: How to call the struts action (in ext) from a portlet ??
June 13, 2012 1:33 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Hi Lalit,
I did almost the same configuration which you mentioned for struts-config.xml & tiles-defs.xml.
In my case its not taking me to the destination jsp... I am on to the same page.(My action class is not even called).
And ya I want to tell you that I am using Liferay 6.... may be thats why its not working for me...
Is their any other way to do the same for liferay 6 ??

Thanks
Ruchi
ruchi sharma
RE: How to call the struts action (in ext) from a plugin portlet ??
June 13, 2012 1:45 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Hello Amit,
Thanks for telling me the other way to do it, I'll go through the links try to do , if it matches my required conditions.
And i'll get back to you.
And as mentined by Lalit in previous post I did the same thing to call the (new) struts action (not overiding the existing one) from my plugin portlet, is it not possible in liferay 6 ??

Regards
Ruchi
ruchi sharma
RE: How to call the struts action (in ext) from a plugin portlet ??
June 15, 2012 3:28 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

Hello friends,
Its working now....
Their was problem in "PortletUrl"
Now my portlet Url is like this :
PortletURL redirectURL = PortletURLFactoryUtil.create(request, PortletKeys.WIKI, themeDisplay.getPlid(), ActionRequest.ACTION_PHASE);
redirectURL.setWindowState(WindowState.NORMAL);
redirectURL.setParameter("my_param_01", "01");
and rest all the configuration is similar as Lalit posted.

Thanks
Ruchi
Chintan Akhani
RE: How to call the struts action (in ext) from a plugin portlet ??
June 15, 2012 4:20 AM
Answer

Chintan Akhani

Rank: Regular Member

Posts: 111

Join Date: March 13, 2008

Recent Posts

for 'post' method below is the alternate approach to call your custom method.

<portlet:actionURL var="myURL1" name="myURL1">
<portlet:param name="struts_action" value="/" />
</portlet:actionURL>

If your method type is 'get' than below is the way to create a url.

<portlet:renderURL var="myURL2">
<portlet:param name="struts_action" value="/blogs/edit_entry" />
</portlet:renderURL>
Priya Pratheep
RE: How to call the struts action (in ext) from a portlet ??
March 31, 2013 8:34 PM
Answer

Priya Pratheep

Rank: Junior Member

Posts: 34

Join Date: March 13, 2013

Recent Posts

Hi I am new to struts and Liferay I don't know how to handle my code in tiles-defs.xml Below is my code


ProjectMgmtAction .java

 1public class ProjectMgmtAction extends Action{
 2   
 3    private Logger logger = LogManager.getLogger(ProjectMgmtAction.class);
 4    @Override
 5    public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) throws Exception{
 6       
 7        logger.debug("----------------------- inside ProjectMgmtAction --------------------------------");
 8        if (form!=null)
 9            logger.debug("form = " +form.getClass().toString());
10        else
11            logger.debug("form=null");
12        if (form==null){
13            String userid = request.getRemoteUser();
14            logger.debug("userid = " +userid);
15            request.setAttribute("APSE_USER_ID", userid);
16        }
17        else if (form instanceof DynaActionForm){
18            logger.debug("----------------------- inside DynaActionForm --------------------------------");
19            
20            DynaActionForm actionform=(DynaActionForm)form;
21       
22            String procode = (String)actionform.get("procode");
23            request.setAttribute("procode", procode);            
24   
25        }
26        else
27            logger.error("form is not instanceof DynaActionForm");
28            
29        return mapping.findForward("continue");
30    }
31}


portlet.xml

 1    <portlet-name>apse-projectmgmt-portlet</portlet-name>
 2        <display-name>APSE Project Management</display-name>
 3        <portlet-class>com.bmtap.apse.projectmgmt.portlet.ProjectMgmtPortlet</portlet-class>
 4        <init-param>
 5            <name>ServletContextProvider</name>
 6            <value>com.liferay.util.bridges.struts.LiferayServletContextProviderWrapper</value>
 7        </init-param>
 8        <init-param>
 9            <name>ViewPage</name>
10            <value>/apse-projectmgmt-portlet/portlet_action/apse-projectmgmt-portlet/viewAction</value>
11        </init-param>
12       
13        <init-param>
14            <name>view-action</name>
15            <value>/portlet_action/apse-projectmgmt-portlet/viewAction1</value>
16        </init-param>


struts-config.xml file
1    <action path="/portlet_action/apse-projectmgmt-portlet/viewAction1" type="com.bmtap.apse.projectmgmt.action.ProjectMgmtAction">
2            <forward name="continue" path="/jsp/project_costingsheet2.jsp"></forward>            
3        </action>
4
5        <action attribute="projectCostingSheetForm2" name="DynaFormBean" path="/apse-projectmgmt-portlet/projectCostingSheetAction2"  type="com.bmtap.apse.projectmgmt.action.ProjectMgmtAction">
6            <forward name="continue" path="/jsp/project_costingsheet2.jsp"></forward>
7        </action>


I want to call project_costingsheet2.jsp from portlet B
1. onClick of link in Portlet A, I want display project_costingsheet2.jsp in Portlet B.
2. When you directly access Portlet B, project_list.jsp should be displayed.


for project_list.jsp the struts.xml file have
1<action path="/portlet_action/apse-projectmgmt-portlet/viewAction" type="com.bmtap.apse.projectmgmt.action.ProjectMgmtAction">
2            <forward name="continue" path="/jsp/project_list.jsp"></forward>            
3        </action>


One week I am running behind this...Can anybody help me how to handle my tiles-defs.xml file

Thanks and Regards
Priya