Pages

Thursday, October 7, 2010

getting url parameter value in liferay

Hi All,
If we set url parameter value in normal jsp page like $some_url$?abc=ok. Then normally we can get value using request.getParameter("abc"); very simple.But in liferay I tried it was not working, then how to do in liferay?? not as simple as
request.getParameter("abc"); but little more code. Taking above example
HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
String abc = httpReq.getParameter("abc");

So we will get desired result.
Hope this helps others.

9 comments:

  1. For Struts potlet You can use:
    ActionContext ctx = ActionContext.getContext();
    PortletRequest req = (PortletRequest) ctx.get("struts.portlet.request");
    return HttpServletRequest request = PortalUtil.getHttpServletRequest(req);
    request.getParameter("id");

    And "id" value will return.

    Thanks to kamalkant.

    ReplyDelete
  2. Thanks, it's really helpful.

    By the way, how do we return a specific page with some params (e.g: /some_page?param=abc) on a processAction?
    e.g.
    ....
    public void processAction(
    ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
    ActionRequest actionRequest, ActionResponse actionResponse)

    throws Exception {
    ....
    //bring me back to my profile with my uid with path as:
    // /user-profile?uid=15

    //setForward(actionRequest,"xxxx");
    }
    ...

    ReplyDelete
  3. Hi HungPK,
    have tried using actionResponse.setRenderParameter("abc", "abc"); this parameter once set u will get in render method like this String abc = renderRequest.getParameter("abc");
    Hope this helps you
    KamalKant

    ReplyDelete
  4. Thanks thanks!! Finally i find what i search :-))

    ReplyDelete
  5. Thank you. Simple and it works :-)

    ReplyDelete
  6. Thank you. Simple and it works :-)

    ReplyDelete
  7. Thank you. Simple and it works! :-)

    ReplyDelete
  8. Thanks kamalkant rajput, it really help me :)

    ReplyDelete