Tuesday, November 5, 2013

How to get parameter's value from URL in Liferay Portlet

To get a parameter's value from URL, eg http://www.kianworknotes.com/myPage.jsp?myName=kian.
from a normal web application.
We just need to get the parameter from the request.
String myName = request.getParameter("myName");  // value is kian

But in Liferay web application, It is unable to get the parameter easily with the above code.
Because the request object in Liferay is a modified PortletRequest insted of HttpServletRequest.

Thus, the first step to request a parameter value from Liferay URL, is to convert the PortletRequest object to HttpServletRequest.
HttpServletRequest request = PortalUtil
 .getHttpServletRequest((PortletRequest) FacesContext

HttpServletRequest oriRequest = PortalUtil

Then we can get parameter's value like the above code.
String myName = oriRequest.getParameter("myName");  // value is kian


1 comment:


Related Posts Plugin for WordPress, Blogger...