Tuesday, January 15, 2013

Having Multiple Instances for Liferay Portlet

Use: For allowing to add more than one portlet instance on same page (where each portlet instance has uniquely generated portlet-id).

How to:
a. Update "liferay-portlet.xml" configuration as:
 <portlet>  
    ...  
   <instanceable>true</instanceable>  
   <!-- <scopeable>true</scopeable>  
   <ajaxable>false</ajaxable> -->  
    ...  
 </portlet>  
b. In JSP files (eg. view.jsp) append unique portlet-id to (AJAX) URL parameters as:
 "<portlet:namespace />myparam1=" + someparamval;  
c. In Java files get the unique portlet-id as:
 public String render(PortletConfig config, RenderRequest renderRequest, RenderResponse renderResponse) {  
   ...  
   System.out.println("Portlet Id:" + PortalUtil.getPortletId(renderRequest));  
   System.out.println("Portlet Namespace:" + PortalUtil.getPortletNamespace(PortalUtil.getPortletId(renderRequest)));  
   ...  
 }  
Points to be considered:
a. URL parameters may conflict
b. Any kind of refresh may affect all instances together
c. Preferences may conflict
d. If preference names are modified then existing Production user preference data will be lost
e. Overall performance may deteriorate

Effect:
a. If a normal URL parameter say "param1"  would need to be sent from jsp / js as "portletuniqueid_param1"
b. If a normal URL parameter say "param1"  would need to be read in java as "portletuniqueid_param1"

No comments: