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()
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.
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
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.
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.
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
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.
A subclass of
GenericPortlet should either use one of the following annotations:
The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.