Difference between JSR 168 and JSR 286 Portlet life Cycle
JSR 168 Portlet Life Cycle
1. void init(PortletConfig config):
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 initialise a portlet. This method is called only one time during the portlet life cycle.
2. void render(RenderRequest request, RenderResponse response):
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"/>
<portlet:renderURL var="myURL"/>
3. void processAction(ActionRequest request, ActionResponse response)
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
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.
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. void 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.
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.
JSR 286 Portlet Life Cycle
JSR 286 Portlet Life Cycle also have all above JSR 168 4 methods, there are 2 new method introduce in JSR 286.
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.
6. void serveResource(ResourceRequest request, ResourceResponse response)
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.
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"/>
<portlet:resourceURL var="myResourceUrl"/>