• JSR 286 Portlet Life Cycle

    Posted on October 22, 2014 by Hamidul Islam in Liferay.

    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


    Post Tagged with ,

4 Responses so far.

  1. ram says:

    A nice and excellent explanation clearly explained. Thanks.

  2. Dinesh says:

    Nicely explained. Thanks

  3. sangam says:

    Nice explanation of portlet lifecycle.

  4. Dmitry says:

    Thanks for the post. Nice and simple!

Top
%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

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.

Close