Pages

Monday 7 May 2012

Available implicit objects Liferay JSP page

Available implicit objects Liferay JSP page
On a normal JSP page, some objects are implicitly available. In addition, we can get several others in Liferay using the taglibs. But we don't know all. So, lets become a technical James Bond and investigate about it. :D

Lets see about normal JSP first:
These objects are created by the container automatically and the container makes them available to us. Since these objects are created automatically by the container and are accessed using standard variables; and that is why, they are called implicit objects. They are parsed by the container. They are available only within the jspService method and not in any declaration.

These are 9 objects.
  1. request     (javax.servlet.ServletRequest)
  2. response    (javax.servlet.ServletResponse)
  3. out         (javax.servlet.jsp.JspWriter)
  4. pageContext (javax.servlet.jsp.PageContext)
  5. session     (javax.servlet.http.HttpS)
  6. application (javax.servlet.ServletContext)
  7. config      (javax.servlet.ServletConfig)
  8. page        (java.lang.Object)
  9. exception   (java.lang.Throwable)

Now, lets ebter the liferay context:

The following statements  will give 14 default objects :
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
  1. actionRequest              (javax.portlet.ActionRequest)
  2. actionResponse             (javax.portlet.ActionResponse)
  3. eventRequest               (javax.portlet.EventRequest)
  4. eventResponse,             (javax.portlet.EventResponse)
  5. portletConfig,             (javax.portlet.PortletConfig)
  6. portletName,               (java.lang.String portletName ;
  7. portletPreferences,        (javax.portlet.PortletPreferences)
  8. portletPreferencesValues,  (java.util.Map)
  9. portletSession,            (javax.portlet.PortletSession)
  10. portletSessionScope,     (java.util.Map)
  11. renderRequest,           (javax.portlet.RenderRequest)
  12. renderResponse,          (javax.portlet.RenderResponse)
  13. resourceRequest,         (javax.portlet.ResourceRequest)
  14. resourceResponse         (javax.portlet.ResourceResponse)
And the following statements will give 18 default objects :

<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<liferay-theme:defineObjects />

and the type of each object as follows :
  1. themeDisplay         (com.liferay.portal.theme.ThemeDisplay)
  2. company              (com.liferay.portal.model.Company)
  3. account              (com.liferay.portal.model.Account)
  4. user                 (com.liferay.portal.model.User)
  5. realUser             (com.liferay.portal.model.User)
  6. contact              (com.liferay.portal.model.Contact)
  7. layout               (com.liferay.portal.model.Layout)
  8. layouts              (java.util.List)
  9. plid                 (java.lang.Long)
  10. layoutTypePortlet    (com.liferay.portal.model.LayoutTypePortlet)
  11. scopeGroupId         (java.lang.Long)
  12. permissionChecker    (com.liferay.portal.security.permission.PermissionChecker)
  13. locale              (java.util.Locale)
  14. timeZone            (java.util.TimeZone)
  15. theme               (com.liferay.portal.model.Theme)
  16. colorScheme         (com.liferay.portal.model.ColorScheme)
  17. portletDisplay      (com.liferay.portal.theme.PortletDisplay)
  18. portletGroupId      (java.lang.Long)

These default objects can be acquired using pageContext which is an implicit object of JSP. Use the following code for getting default objects.

ActionRequest actionRequest = (ActionRequest) pageContext.findAttribute(“actionRequest”);

  Hope this will help. 


Thanks to Apoorva prakash for sharing this :
http://apoorvaprakash.blogspot.com/2011/09/available-implicit-objects-liferay-jsp.html

No comments:

Post a Comment