Portlet Define Objects

Define Objects


While developing portlet in Liferay we widely use Portlet Define Objects tag in our JSP code. In this article we will try to understand the use of Portlet Define Objects  using  portlet:defineObjects tag  in Liferay Portlet. 


Why this tag is required:
By using this tag we actually inherit some predefined objects in our JSP which ease our development process. Without using this tag we might have to write a bunch of code to get all the objects in our JSP. 

JSR 168 (Portlet Specification 1.0):

 According to JSR 168 a JSP file must have below taglib declaration

<%@ taglib uri=”http://java.sun.com/portlet” prefix=”portlet” %>

Then we can use the define object tag as <portlet:defineObjects /> in our JSP page. According to JSR 168 this tag will provide only 3 objects in our JSP

RenderRequest  renderRequest
RenderResponse  renderResponse
PortletConfig  portletConfig


Note Note 1: A portlet container which supports JSR 286 should also support JSR 168.

Note 2: Liferay Portal supports JSR 286. This means it also supports JSR 168.

 Note 3: The defineObjects tag must not define any attribute and it must not contain any body.


JSR 286(Portlet Specification 2.0):

According to JSR 286 a JSP file must have below taglib declaration

<%@ taglib uri=”http://java.sun.com/portlet_2_0″ prefix=”portlet”%>

and <portlet:defineObjects />
According to JSR 286 it will provide below objects in our JSP

i) RenderRequest renderRequest when included from within the render method, null or not defined otherwise.

ii) ResourceRequest resourceRequest when included from within the serveResource method, null or not defined otherwise.

iii) ActionRequest actionRequest when included from within the processAction method, null or not defined otherwise.

iv) EventRequest eventRequest when included from within the processEvent method, null or not defined otherwise.

v) RenderResponse renderResponse when included from within the render method, null or not defined otherwise.

vi) ResourceResponse resourceResponse when included from within the serveResource method, null or not defined otherwise.

vii) ActionResponse actionResponse when included from within the processAction method, null or not defined otherwise.

viii) EventResponse eventResponse when included from within the  processEvent method, null or not defined otherwise.

ix) PortletConfig portletConfig

x) PortletSession portletSession, providing access to the portletSession, does not create a new session, only returns an existing session or null if no session exists.

xi) Map<String, Object> portletSessionScope, providing access to the portletSession attributes as a Map equivalent to the PortletSession.getAttributeMap() call, does not create a new session, only returns an existing session. If no session attributes exist this method returns an empty Map.

xii) PortletPreferences portletPreferences, providing access to the portlet preferences.

xiii) Map<String, String[]> portletPreferencesValues, providing access to the portlet preferences as a Map, equivalent to the ortletPreferences.getMap() call. If no portlet preferences exist this method returns an empty Map.

About The Author

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top
%d