RE: action phase render parameter gets overwritten

thumbnail
Philippe Thibault, modified 7 Years ago. Junior Member Posts: 46 Join Date: 9/11/12 Recent Posts
Hi,

I have come up with a situation where a parameter I set in action phase to go to render is overwritten back to the value previously set in the request that called the action. Here is an example of what I'm saying:

In my view.jsp I create the actionURL with a parameter:


<portlet:actionurl name="myaction" var="myactionURL">
    <portlet:param name="P" value="from_view_jsp" />
</portlet:actionurl>


In the portlet code action method I set this parameter to another value for the render phase :


public void myaction (ActionRequest actionRequest, ActionResponse actionResponse) {
    actionResponse.setRenderParameter("P", "from_action");
}


What I get in render phase after action phase is that parameter named "P" value is "from_view_jsp", when I expected it to be "from_action" as set in action.

Are my expectation wrong, or is it a bug? Are request parameter copied back after action phase for render and overwritting my parameter setting?

thanks for your help

Phil
asha ramoliya, modified 7 Years ago. New Member Posts: 5 Join Date: 5/24/18 Recent Posts
Hi,
Did you try following code to get value in render method?
1)renderRequest.getParameter("P");
2)If you can access ParamUtil,try ParamUtil.getString(renderRequest,"P");
thumbnail
Philippe Thibault, modified 7 Years ago. Junior Member Posts: 46 Join Date: 9/11/12 Recent Posts
Hi asha,

Yes I am looking at request parameter in render method. I am looking at the complete map like this :


@Override
public void doView (RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException 
{
        System.err.println ("renderRequest parameter map:");
        Map<string, string[]> pmap = renderRequest.getParameterMap ();
        for (Map.Entry<string, string[]> entry : pmap.entrySet ())
        {
          System.err.println (String.format ("renderRequest parametermap %s -- %s", entry.getKey (), Arrays.toString (entry.getValue ())));
        }

        super.doView (renderRequest, renderResponse);
    }
</string,></string,>


As for using ParamUtil.getString() it is the same as expected since this is just a wrapper around renderRequest.getParameter().

So, any idea why my parameters are overwritten after action phase? Is there any "behind the scene" copying of request parameter back to render phase going on?
thumbnail
Philippe Thibault, modified 7 Years ago. Junior Member Posts: 46 Join Date: 9/11/12 Recent Posts

anyone have a guess at why a request paramater I change value with setRenderparameter() gets overwritten back to the request original value?

thumbnail
Minhchau Dang, modified 7 Years ago. Liferay Master Posts: 598 Join Date: 10/22/07 Recent Posts
Philippe Thibault:

anyone have a guess at why a request paramater I change value with setRenderparameter() gets overwritten back to the request original value?

If your portlet class extends Liferay's MVCPortlet, it has code that specifically copies action parameters, if the init-param copy-request-parameters is not explicitly set to false (default is true).

thumbnail
Philippe Thibault, modified 7 Years ago. Junior Member Posts: 46 Join Date: 9/11/12 Recent Posts

Thanks Minhchau that's the answer I was looking for. Another pitfall for me to fall into ...