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.

Locale message in javascript of .jsp and in .js

As continue to my previous blog, sometimes we get requirement to display locale message in 'Notifications' or 'Alerts'. It is easy to diplay in jsp page in labels but how to display in alerts then the below is an example which will help you on this type of requirement.

example :-
.jsp code :-
 
function modeAlert(){
        alert("<liferay-ui:message key="payment"/>");
    }

.js code :- 

 Liferay.Language.get('key');

--------------------------------------------------------------------------

Path for Language properties file :-  src/content/Language_en_US.properties

Language_en_US.properties :-  ex: (Key : Vlaue)
  
  payment: Payment 

Language_ms_MY.properties :-  ex: (Key : Vlaue)

  payment: Pembayaran

When ever you use the above key(first way or second way) depending upon the current locale the value will be diplayed.

WEB-INF/Portlet.xml :- The entry in the portlet.xml is also mandatory then only you can able to see the values otherwise you can see only key as output.

<portlet>
<portlet-name>request</portlet-name>
<display-name>Request</display-name>
<portlet-class>com.Request</portlet-class>
<init-param>
</init-param>
<supports>
</supports>
<supported-locale>en_US</supported-locale>
<supported-locale>ms_MY</supported-locale>
<resource-bundle>content.Language</resource-bundle>
<portlet-info>
  </portlet-info>
 </portlet>

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. ...