Foros de discusión

Struts action defined in my portlet button action is not called

Jan Tošovský, modificado hace 12 años.

Struts action defined in my portlet button action is not called

Liferay Master Mensajes: 566 Fecha de incorporación: 22/07/10 Mensajes recientes
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.

<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui"%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet"%>

<portlet:defineobjects />

<portlet:actionurl var="addLayouts">
    <portlet:param name="struts_action" value="/layouts_admin/add_layouts" />
</portlet:actionurl>

<aui:form action="<%= addLayouts %>" method="post" name="fmcc" id="fmcc">
    <aui:fieldset>
        <aui:input type="textarea" name="layoutsInfo" />
    </aui:fieldset>
    <aui:button-row>
        <aui:button type="submit" value="addLayouts" />
    </aui:button-row>
</aui:form>


What is wrong in my code?

Jan
Jan Tošovský, modificado hace 12 años.

RE: Struts action defined in my portlet button action is not called

Liferay Master Mensajes: 566 Fecha de incorporación: 22/07/10 Mensajes recientes
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ý, modificado hace 12 años.

RE: Struts action defined in my portlet button action is not called

Liferay Master Mensajes: 566 Fecha de incorporación: 22/07/10 Mensajes recientes
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:
PortletURL redirectURL = PortletURLFactoryUtil.create(request, PortletKeys.WIKI, themeDisplay.getPlid(), ActionRequest.ACTION_PHASE);
redirectURL.setWindowState(WindowState.NORMAL);
redirectURL.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ý, modificado hace 12 años.

RE: Struts action defined in my portlet button action is not called

Liferay Master Mensajes: 566 Fecha de incorporación: 22/07/10 Mensajes recientes
I've just found that my action calls struts action, but no form parameters are passed if not explicitly set to the redirectURL variable.


&lt;%
PortletURL redirectURL = PortletURLFactoryUtil.create(request, PortletKeys.WIKI, themeDisplay.getPlid(), ActionRequest.ACTION_PHASE);
redirectURL.setWindowState(WindowState.NORMAL);
redirectURL.setParameter("struts_action", "/wiki/my_action");
redirectURL.setParameter("my_param_01", "01");
%&gt;

<aui:form action="<%= redirectURL %>" method="post" name="fm">
        <aui:input type="text" name="my_param_02" />
        </aui:form>
thumbnail
Amit Doshi, modificado hace 11 años.

RE: Struts action defined in my portlet button action is not called

Liferay Master Mensajes: 550 Fecha de incorporación: 29/12/10 Mensajes recientes
Hi Jan,

I think the below code should work for you.


<aui:form action="<portlet:actionURL windowState=" <%="WindowState.MAXIMIZED.toString()" %>"&gt;<portlet:param name="struts_action" value="/wiki/my_action" /><portlet:param name="my_param_01" value="01" />" method="post" name="<portlet:namespace />fm"&gt;
    <aui:fieldset>
<aui:input type="text" name="my_param_02" />
    </aui:fieldset>
    <aui:button-row>
        <aui:button type="submit" />
    </aui:button-row>
</aui:form>



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


public void processAction(
			ActionMapping mapping, ActionForm form, PortletConfig config,
			ActionRequest req, ActionResponse res)

		throws Exception {
		
		String bookTitle = req.getParameter("my_param_02");
}




Hope it works for you.

Regards,
Amit Doshi
ruchi sharma, modificado hace 11 años.

RE: Struts action defined in my portlet button action is not called

Junior Member Mensajes: 95 Fecha de incorporación: 24/03/11 Mensajes recientes
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