Monday, July 6, 2015

Reading the parameters from URL in Liferay

In Liferay some times we will face an issue to read the parameters from the URL (it may be actionURL or renderURL), it will give null value when you try to read the parameters with simple 'actionRequest' or 'renderRequest' in such scenario we need to read the parameters from the 'OriginalServletRequest'. the below example clearly shows how to read those parameters.

imports :-
import javax.servlet.http.HttpServletRequest;
import com.liferay.portal.util.PortalUtil;
import javax.portlet.ActionRequest;

java code :-

HttpServletRequest originalRequest  = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(actionRequest));

String STATUS = originalRequest.getParameter("STATUS");

//actionRequest for action method and renderRequest for rendermethod.

jsp code :- suppose you need to read in your jsp page then read the parameter in the following way.

HttpServletRequest originalRequest  = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));

String STATUS = originalRequest.getParameter("STATUS");

Note:- Suppose we are reading the parameters from the URL which are passing by any third party server(ex: payment gateways) in such type of scenarios, we need to read the parameters in the above way.

2 comments:

nasreen basu said...

Your posts is really helpful for me.Thanks for your wonderful post. I am very happy to read your post. It is really very helpful for us and I have gathered some important information from this blog. liferay training in hyderabad

Inthiyaz Shaik said...

Welcom Nasreen.

Liferay DXP JNDI Data Source Cofiguration

 This Blog will help us to learn about the JNDI Data Source Configuration in Liferay DXP. We have tested this with Liferay 7.3 with Tomcat. ...