JSR 286 Portlet Life Cycle

portlet life cycle


Beginners who just started learning java based portlet development for them its very important to understand whats portlet life cycle.Without knowing portlet life cycle its almost impossible to develop a portlet. We should have a clear understanding of portlet life cycle methods. This article explains all the portlet life cycle methods and their usage. 


6 Portlet Life Cycle Methods

void init(PortletConfig config)
void render(RenderRequest request, RenderResponse response)
void processAction(ActionRequest request, ActionResponse response)
void processEvent(EventRequest request, EventResponse response)
void serveResource(ResourceRequest request, ResourceResponse response)
void destroy()

1. init

This method is called by the portlet container to indicate to a portlet that the portlet is being placed into service. This method used to initialize a portlet. This method is called only one time during the portlet life cycle.

2. render

When a portlet is displayed in the portal page this method is called. Render method is responsible to generate HTML content. We can create render URL to invoke render method. For example

<portlet:renderURL var=”myURL”/>

3. processAction

When we invoke action URL the processAction method is called. A process action is generally used to process submitted form or writing data to database. For example

<portlet:actionURL var=”myURL” name=”process”/>

As soon as a process action is invoked it invoke render method. If a portal page contains five portlets then all the five render methods will be called either in parallel or one after another.

4. processEvent

Process Event method is used to process an event. In JSR 168 there was no no process event method. It was introduced in JSR 286. This portlet life cycle method has important role in implementing event based inter portlet communication (IPC). As soon as process event method is completed the portlet container invokes render method. 

5. serveResource

Called by the portlet container to allow the portlet to generate the resource content based on its current state. The portal / portlet container must not render any output in addition to the content returned by the portlet. The portal / portlet container should expect that the portlet may return binary content for a renderResource call. This portlet life cycle method is added in JSR 286.

This method is basically required to generate non HTML based content like JSON, XML etc. We can implement AJAX using this method. A serveResource method can be invoked by creating resource URL. For example

<portlet:resourceURL var=”myResourceUrl”/>

6. destroy

Called by the portlet container to indicate to a portlet that the portlet is being taken out of service. The default implementation does nothing. When a portlet is undeployed this method is called by the portlet container.


3 Annotations

A subclass of GenericPortlet should either use one of the following annotations:

@ProcessAction

@ProcessEvent

@RenderMode


About The Author

4 thoughts on “JSR 286 Portlet Life Cycle”

Leave a Reply

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

Scroll to Top