• Generic Portlet

    Posted on March 14, 2014 by Hamidul Islam in .

    Generic Portlet

    A generic portlet is purely JSR 286 compliant until and unless if we don't use any Liferay API or configuration files. A generic portlet can be deployed in any java based portal which supports JSR 286.

    To develop generic portlet we generally create our own custom class which generally extends GenericPortlet abstract class.

    Step1 : Lets create a custom class which extends GenericPortlet 

    Generic Portlet
    package com.proliferay.demo;import java.io.IOException;import javax.portlet.GenericPortlet;
    import javax.portlet.PortletException;
    import javax.portlet.PortletRequestDispatcher;
    import javax.portlet.RenderRequest;
    import javax.portlet.RenderResponse;import com.liferay.portal.kernel.log.Log;
    import com.liferay.portal.kernel.log.LogFactoryUtil;
    * @author Pro Liferay
    public class DemoGenericPortlet extends GenericPortlet{public void init() {viewTemplate = getInitParameter("view-template");

    public void doView(
    RenderRequest renderRequest, RenderResponse renderResponse)
    throws IOException, PortletException {include(viewTemplate, renderRequest, renderResponse);


    protected void include(
    String path, RenderRequest renderRequest,
    RenderResponse renderResponse)
    throws IOException, PortletException {PortletRequestDispatcher portletRequestDispatcher =

    if (portletRequestDispatcher == null) {
    _log.error(path + " is not a valid include");
    else {
    portletRequestDispatcher.include(renderRequest, renderResponse);

    protected String viewTemplate;

    private static Log _log = LogFactoryUtil.getLog(DemoGenericPortlet.class);


    We will explain each of the method one by one.

    public void init()  
     Once we deploy the portlet this method will be called first and it willlookfor view-template parameter in the portlet.xml file. This is calledinitialization parameter. Lets define this parameter in portlet.xml<init-param>

    So after deployment of the portlet the value of protected String

    viewTemplate would beviewTemplate = "/jsp/genericdemo/view.jsp";

    So we have initialized viewTemplate in init method.

    public void doView()

    When the portlet will be added to the portal page this method will be

    executed.  This is method is called basically for rendering the portlet. You

    might be thinking how the JSP page is rendered.  Here are the sequences

    1. When you add the portlet in the portal page doView method will be called

    2. doView method call  include(viewTemplate, renderRequest, renderResponse);

    3. Inside include method

    PortletRequestDispatcher portletRequestDispatcher =

    where the path is jsp path which is nothing but /jsp/genericdemo/view.jsp

    Now deploy the portlet ....

    Generic Portlet



%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.