1
votes

Can someone help me? I have custom parameter, "statusparam" for example. And I want to do something like this:

actionResponse.sendRedirect(redirect + "&statusparam=error");

But the problem is that custom parameter is non-friendly to liferay and liferay doesn't see it in my render method:

String status = ParamUtil.getString(renderRequest, "statusparam");

How can I generate liferay-friendly URL with my custom parameters? Or how can I take them?

2
The problem is that your parameter must be in proper namespace of the portlet. How do you generate the redirect variable? If you use the PortletURL (e.g. via PortletURLUtil), you can use the setParameter(String name, String value) method.Jozef Chocholacek
@jahra, Did you find suitable solution?Parkash Kumar

2 Answers

2
votes

Pattern 1: setRenderParameter
One way is to set render parameter(s) in action phase using setRenderParameter as following:

actionResponse.setRenderParameter("statusparam", "error");

and then get using:

String status = renderRequest.getParameter("statusparam");

or

String status = ParamUtil.getString(renderRequest, "statusparam");

Pattern 2: Global property
Other way is to put a global property in action class, assign it value in action method then it would be accessible in render method as well.

public class MyPortletAction extends GenericPortlet {
    String statusparam = "";

    public void doView(RenderRequest renderRequest, RenderResponse renderResponse) {

        if(statusparam != ""){
            // Perform operation as per your requirement
        }
    }

    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) {

        // Set statusparam here:
        statusparam = "error";
    }
}

Pattern 3: queryString
While, if you want to pass it as queryString parameter, then you can extract it from HttpServletRequest object in render phase as following:

HttpServletRequest request = PortalUtil.getHttpServletRequest(renderRequest);
String statusparam = request.getParameter("statusparam");
2
votes

There are two ways to get parameter values which don't have namespace prefix.

  1. Add following line in liferay-portal.xml :

    < requires-namespaced-parameters > false < / requires-namespaced-parameters >

and you can read like:

String status = ParamUtil.getString(renderRequest, "statusparam");
  1. Or use HttpServletRequest like:
HttpServletRequest request = PortalUtil.getHttpServletRequest(renderRequest);
String statusparam = request.getParameter("statusparam");

Edit: If you only need this parameter in render method of same portlet, use setRenderParameter like:

actionResponse.setRenderParameter("statusparam", "error");

Remember, it will not add in URL and also will not available in another portlets