Total Pageviews

Sunday, September 4, 2016

Liferay: A note on Portlet Namespace

Portlet namespace is a unique ID associated to each instance of the portlet provided by the portlet container.

When a team is working on a Liferay project, there are several portlets are created. From my experience, I have seen projects having 150+ portlets. So it’s very difficult to track the client side elements, such as JavaScript function, HTML elements IDs etc., which are being written by several developers. Portlet Namespace is a solution of the same. This tag returns the ID of the portlets which can prefixed with client side elements. This tag returns the ID of the portlet, with instance ID in case of instantiable portlet. Portlet Namespace can be used by several ways, to day we’ll see getting it by tag and PortletResponse object.

Non Instantiable portlet’s ID:
_empiricismportlet_WAR_namespaceportlet_
_{Portlet WAR ID}_WAR_{Portlet ID}_

Instantiable portlet
_empiricismportlet_WAR_namespaceportlet_INSTANCE_rwgp46_
_{Portlet WAR ID}_WAR_{Portlet ID}_INSTANCE_{random ID generated by Liferay}_

Usage of <portlet:namespace />
<portlet:namespace /> gets converted to ID at the time of JSP’s conversion to class.

In JavaScript


So internally the mark-up generated will be as follows:

Usage by PortletResponse

Namespace can be obtained by any of the PortletResponse objects:

  1. renderResponse.getNamespace()
  2. actionResponse.getNamespace()
  3. resourceResponse.getNamespace()


for example, I’ll consider renderResponse object is available on the JSP


To conclude, both the approached are same however <portlet:namespace /> most preferred way. However second one is needed when you are in controller class, utility methods or TLDs.

That’s all for today. Thanks for reading and have a nice day.

Monday, August 29, 2016

Liferay: Understanding theme:defineObjects


In the previous post, we have gone through the implicit objects provided by <portlet:defineObjects/>. In the continuation, today we will go through the implicit objects provided by <theme:defineObjects />.

Similar to <portlet:defineObjects/>, <theme:defineObjects /> is also an empty tag without any attribute, and must be included after the mentioned directive. Lets see the objects:
  1. ThemeDisplay themeDisplay - contains attributes such as groupId, company id, user id, if the user is logged in, etc..
  2. Company company – Portal instance specific information
  3. Account account – current user’s account object
  4. User user – logged in user’s attributes
  5. User realUser – in case of impersonation, gets the logged in user’s id
  6. Contact contact – current user’s contact object
  7. Layout layout – current page attributes
  8. List<Layout> layouts
  9. long plid - current portlet layout id
  10. LayoutTypePortlet layoutTypePortlet – object having information about portlets on the current layout
  11. long scopeGroupId – groupid of the current scope
  12. PermissionChecker permissionChecker – attributes regarding surrent user’s permission
  13. Locale locale – current user’s locale, determined by JVM
  14. TimeZone timeZone – current user’s timezone, determined by JVM
  15. Theme theme – attributes of current theme being rendered on the page
  16. ColorScheme colorScheme – attributes of the current colour scheme of the current theme
  17. PortletDisplay portletDisplay – attributes regarding name, ID, portlet mode etc.
That’s all for today. Thanks for reading and have a nice day.

Sunday, August 28, 2016

Liferay: Understanding portlet:defineObjects

There is so much confusion about the implicit objects provided by <portlet:defineObjects/> tag on JSP as developers cannot see them easily. Experienced developers know what is available and they can use them freely. Here is a cheat sheet for the same.

<portlet:defineObjects/> is an empty tag without any attribute, and must be included after the mentioned directive.


JSR -286 (Portlet 2.0) have objects available from the following 13 objects, depending upon the origin of render, which lies in 3 categories:

  1. Request Objects
    1. RenderRequest – if the origin of request is from render phase
    2. ActionRequest - if the origin of request is from action phase
    3. ResourceRequest - if the origin of request is from ajax (serveResource)
    4. EventRequest - if the origin of request is from event (processEvent)
  2. Response Objects
    1. RenderResponse - if the origin of request is from render phase
    2. ActionResponse - if the origin of request is from action phase
    3. ResourceResponse - if the origin of request is from ajax (serveResource)
    4. EventResponse - if the origin of request is from event (processEvent)
  3. Portlet Objects
    1. PortletConfig
    2. PortletSession
    3. Map<String, Object> - contains list of all portletSessionAttributes
    4. PortletPreferences
    5. Map<String, String[]> - contains list of all portletPreferences

That’s all for today. Thanks for reading and have a nice day.