Understanding standard portlet life cycle

A portlet is managed through a well defined life cycle that defines how it is loaded,
instantiated and initialized, how it handles requests from clients, and how it is taken out of service. This life cycle of a portlet is expressed through the init, processAction, render and destroy methods of the Portlet interface.


  • init: When portal server gets request for a page it will check if all the portelts on that page are initialized or not if not it will create new instance of portlet call its init() method.

  • processAction: Whenever user clicks on an action URL or submits a form to action URL the portal server will call processAction() method of the portlet. IN this method your suppose to change state of the portlet by setting render parameter, storing data in database,..etc

  • render: THis is the most common method of the portlet, whenever you go to page which has the portlet or click on the action URL of any other portlet on the page or click on the render URL within the same portlet, refresh page, the render method of the portlet will be called. The render method is responsible for generating markup of the portlet based on its current state.

  • destroy: When portal server decides to take portlet out of the request it will call its destroy method to give it a chance to release resources



Important Point: The Portal server will create only one instance of portlet per JVM and it will create different threads for every request and call appropriate methods of portlets from that thread.

In addition to this your portlet can decide to implement EventPortlet interface which says that portlet can be target of event (Target of inter portlet communication). The EventPortlet interface defines processEvent() method that you should override to implement the logic that should be executed when portlet receives event. THis is useful if you want to use inter portlet communication

If your portlet wants to support Ajax access then you can also implement ResourceServingPortlet interface, that defines serveResource() method. Once you define this method you can create a resource URL from your portlet using resourceURL tag and make request to the URL to get the fragment of portlet. This helps you avoid creating a Servlet in same application as that of the portelt just to support Ajax

No comments:

Post a Comment