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.
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.
Then we can get parameter's value like the above code.
Done!!
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
.getCurrentInstance().getExternalContext().getRequest());
HttpServletRequest oriRequest = PortalUtil
.getOriginalServletRequest(request);
Then we can get parameter's value like the above code.
String myName = oriRequest.getParameter("myName"); // value is kian
Done!!
Thank You so much
ReplyDelete