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:

Java web development said...

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.

HungPK said...

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");
}
...

Unknown said...

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

Anonymous said...

Thanks thanks!! Finally i find what i search :-))

Felipe Ribeiro said...

Thanks! It works...

Unknown said...

Thank you. Simple and it works :-)

Unknown said...

Thank you. Simple and it works :-)

Unknown said...

Thank you. Simple and it works! :-)

Noman Ali said...

Thanks kamalkant rajput, it really help me :)