Liferay Portlet Lifecycle

What is Portlet?

a portlet is fragment on a webpage as web application and is used with portlets on the same webpage. There are 2 JSR standards for portlet behavior:

  • JSR 168 (Portlet 1.0 specification):
    •    Focuses on displaying multiple applications on the same page.
    •  It introduces the basic portlet programming model to support the MVC pattern , portlet modes, window states
  • JSR 286 (Portlet 2.0 specification):
    •  Developed to improve the shortcomings of JSR-168
    • Supports Inter-Portlet Communication
    • serving AJAX data
Portlet Life Cycle:
  • Init: The init()  method is called by the portlet container during deployment and reads init parameters defined in portlet.xml file. The Portlet interface exposes the init method as:  void init (PortletConfig config) throws PortletException
    The PortletConfig interface is  to retrieve configuration  from the portlet definition in the deployment descriptor. The portlet can only read the configuration data. The configuration information contains the portlet name, the portlet initialization parameters, the portlet resource bundle and the portlet application context.
  • Render : In this phase portlet generates content and renders on webpage.
    • The  render phase is called in below cases:
      • The page that contains portlet is rendered on web page
      • After completing Action Phase
      • After completing Event Processing phase
    • below is example:
      <portlet:renderURL var=“loadEmployees”> <portlet:param name=”mvcPath”
      value=”/WEB-INF/view/empList.jsp” /> </portlet:renderURL>
      <a href=”<%=loadEmployees%>”>Click here</a>
  • Action:  its result of user actions such as add,edit, delete.
    •  only one portlet can be entered into action phase for a request in a portlet container
    • Any events triggered during the Action phase are handled during the Event phaseof the portlet lifecycle. Events can be used when portlets want to communicatewith each other. The Render phase will be called when all events have been handled.
  • Destroy: The destroy() method will be called when portlet is undeployed from portlet container.

 

 

1 Comment

  1. zeeee

    nice post

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *