Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jan Tošovský
Struts action defined in my portlet button action is not called
January 11, 2012 2:24 AM
Answer

Jan Tošovský

Rank: Expert

Posts: 297

Join Date: July 22, 2010

Recent Posts

Hello Everyone,

I'd like to automate some manual steps. I made a simpe portlet, custom action and created corresponding struts path definition.

When the struts path is entered into the browser navigation bar in the form http://localhost:8080/c/layouts_admin/add_layouts, my action is invoked.

I'd like to perform the same operation on submit button of my portlet and pass a string parameter to it. When the following code is used in view.jsp, the page is rerendered, but that action is not called (strutsExecute or processAction) as I log entering these methods and no message appears in this case.

 1<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui"%>
 2<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
 3<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet"%>
 4
 5<portlet:defineObjects />
 6
 7<portlet:actionURL var="addLayouts">
 8    <portlet:param name="struts_action" value="/layouts_admin/add_layouts" />
 9</portlet:actionURL>
10
11<aui:form action="<%= addLayouts %>" method="post" name="fmcc" id="fmcc">
12    <aui:fieldset>
13        <aui:input type="textarea" name="layoutsInfo" />
14    </aui:fieldset>
15    <aui:button-row>
16        <aui:button type="submit" value="addLayouts" />
17    </aui:button-row>
18</aui:form>


What is wrong in my code?

Jan
Jan Tošovský
RE: Struts action defined in my portlet button action is not called
January 12, 2012 9:32 AM
Answer

Jan Tošovský

Rank: Expert

Posts: 297

Join Date: July 22, 2010

Recent Posts

I haven't made any progress after digging this issue for several hours.
Kingdom for a hint how to call the appropriate action method on the button click in my portlet.

Jan
Jan Tošovský
RE: Struts action defined in my portlet button action is not called
January 13, 2012 12:08 AM
Answer

Jan Tošovský

Rank: Expert

Posts: 297

Join Date: July 22, 2010

Recent Posts

I've found something here http://www.liferay.com/community/forums/-/message_boards/message/6828539
taglib creates a render URL within the current portlet context, which means that the generated URL will try to resolve a render method in your current portlet's controller ... but you want to resolve the render method of another portlet ... you have to generate the requested URL instead


Finally this solution works:
1PortletURL redirectURL = PortletURLFactoryUtil.create(request, PortletKeys.WIKI, themeDisplay.getPlid(), ActionRequest.ACTION_PHASE);
2redirectURL.setWindowState(WindowState.NORMAL);
3redirectURL.setParameter("struts_action", "/wiki/my_action");

Note that struts action context has to match the target portlet (WIKI in this example).

Jan
Jan Tošovský
RE: Struts action defined in my portlet button action is not called
January 13, 2012 3:33 AM
Answer

Jan Tošovský

Rank: Expert

Posts: 297

Join Date: July 22, 2010

Recent Posts

I've just found that my action calls struts action, but no form parameters are passed if not explicitly set to the redirectURL variable.

 1
 2<%
 3PortletURL redirectURL = PortletURLFactoryUtil.create(request, PortletKeys.WIKI, themeDisplay.getPlid(), ActionRequest.ACTION_PHASE);
 4redirectURL.setWindowState(WindowState.NORMAL);
 5redirectURL.setParameter("struts_action", "/wiki/my_action");
 6redirectURL.setParameter("my_param_01", "01");
 7%>
 8
 9<aui:form action="<%= redirectURL %>" method="post" name="fm">
10        <aui:input type="text" name="my_param_02" />
11        <aui:button type="submit" value="my_action />
12</aui:form>


How also param_02 could be pased?
ruchi sharma
RE: Struts action defined in my portlet button action is not called
June 12, 2012 8:20 AM
Answer

ruchi sharma

Rank: Junior Member

Posts: 95

Join Date: March 24, 2011

Recent Posts

HI Jan,
I also want to do the same , unfortunately not able to do so.
Please could you tell me , your struts-config-ext.xml and tiles-defs-ext.xml settings.
Thanks
Ruchi
Amit Doshi
RE: Struts action defined in my portlet button action is not called
June 12, 2012 11:43 AM
Answer

Amit Doshi

Rank: Liferay Master

Posts: 543

Join Date: December 29, 2010

Recent Posts

Hi Jan,

I think the below code should work for you.

 1
 2<aui:form action="<portlet:actionURL windowState="<%= WindowState.MAXIMIZED.toString() %>"><portlet:param name="struts_action" value="/wiki/my_action" /><portlet:param name="my_param_01" value="01" /></portlet:actionURL>" method="post" name="<portlet:namespace />fm">
 3    <aui:fieldset>
 4<aui:input type="text" name="my_param_02" />
 5    </aui:fieldset>
 6    <aui:button-row>
 7        <aui:button type="submit"  />
 8    </aui:button-row>
 9</aui:form>


you can get your parameter in struts portlet as below :-

 1
 2public void processAction(
 3            ActionMapping mapping, ActionForm form, PortletConfig config,
 4            ActionRequest req, ActionResponse res)
 5
 6        throws Exception {
 7       
 8        String bookTitle = req.getParameter("my_param_02");
 9}


Hope it works for you.

Regards,
Amit Doshi