Portlet performs unique operation in each lifecycle execution. These lifecycles are known as portlet phases. Each portlet phase / lifecycle is represented by respective methods in portlet class.
For example, if action method is completed for one portlet then its’ render() method is called along with render() method of all portlets on that page.In this case, other portlets on that page are still generating the response even though user had not directly interacted with them.
Due to this behavior, Portlet specification defines more than one methods to process user request. These methods represent corresponding Portlet Phases.
initially following two portlet phases are defined in JSR-168 (Portlet 1.0) specification
- Render Phase
- Action Phase
- Event Phase
- Resource Serving Phase
JSR-168 has 2 phases while JSR-286 has total 4 phases (JSR-286 is super set of JSR-168)
Following methods represents these portlet phases. These methods are known as Lifecycle of Portlet.
- This method will be called when portlet is deployed and instantiated by portlet container.
- This method will be called to render the content. Represent Render phase.
- This method will be called when any action performed.
- This method will be called when any event is triggered.
- This method will be called when any resource is served with resource URL.
- This method will be called when portlet is un-deployed by portlet container.
These lifecycle methods / portlet phases are managed by Portlet Container. Portlet container is responsible for following tasks.
- Loading class of portlet
- Creating and maintaining the portlet instance
- Initializing the Portlet
- Submitting user request to portlet instance
- Destroying portlet instance when it is undeployed.
Below diagram describes the lifecycle methods of servlet and portlet.
- There is no direct relation between lifecycle methods of portlet and servet.
- This diagram is just to understand lifecycle methods side by side.
- For both Portlet and Servlet, init() and destroy() methods are called by respective container (Portlet and Servlet container).
- In case of Servlet, all requests are served by service() method
- In case of Portlet, user requests are served by different methods like render(), processAction(), processEvent() and serveResource() based on portlet’s current phase.
Explanation of Portlet’s Lifecycle methods
I have given explanation of each Lifecycle methods in separate blog. Below blogs giving detail understanding of each lifecylce method.
- Portlet init phase / Lifecycle method – init()
- Portlet render phase / Lifecycle method – render()
- Portlet action Phase – Portlet Lifecycle method – processAction()
- Portlet serve resource Phase / Lifecycle method – serveResource()
- Portlet Lifecycle method – processEvent() – Available soon