• Portlet Overview

    Posted on March 3, 2014 by Hamidul Islam in .

    Portlet Overview

    Portlets are web components. A collections of portlets make a portal. There are many similarities between portlet and servlet. However unlike servlet it occupies a fraction of the browser.

    According wikipedia:-

    Portlets are pluggable user interface software components that are managed and displayed in a web portal. Portlets produce fragments of markup (HTML, XHTML, WML) code that are aggregated into a portal. Typically, following the desktop metaphor, a portal page is displayed as a collection of non-overlapping portlet windows, where each portlet window displays a portlet. Hence a portlet (or collection of portlets) resembles a web-based application that is hosted in a portal. Some examples of portlet applications are email, weather reports, discussion forums, and news.

    Portlet standards are intended to enable software developers to create portlets that can be plugged into any portal supporting the standards.

    portal-page

    Portlet Development

    Liferay provides a number of portlets for basic to advanced usage of the portal . However sometimes those portlets are not enough for our requirements. A custom portlet has to be built according to our needs.

    There are many frameworks to develop a custom portlet. The most popular frameworks are

    1) Generic Portlet -a generic portlet will work in any JSR compliant portal.

    2) Liferay MVC - its very light weight, easy to use & no external dependency required as liferay provides necessary JAR to develop it.

    3) Spring MVC - very robust and popular.

    4) JSF

    5) Prime Faces - well known for UI components.

    Portlet Life Cycle

    (Based on JSR 286)

    Below are the life cycle methods of a portlet

    1. init()

    At the time of deployment of a portlet this method will be first called. This method is used to initialize the portlet.

    2. processAction()

    This method is used when we need to process a form inputs or we need to interact with the database. Normally by actionURL the process action is invoked from the UI. Its not mandatory to have process action in a portlet. 

    3. render()

    This method is invoked when we add a portlet to the portal page or it can be invoked by renderURL from UI.  This method is mandatory for every portlet.

    Note : If a portlet has processAction then after invoking a processAction it will invoke render method.

    4. destroy()

    This method is called when we undeploy a portlet. Normally cleanup code is put in destroy method.

    5. serveResource()

    This method is used when we need to implement Ajax. For rendering non HTML based content like pdf, JSON, XML etc. this method can be used.

    Normally by  resourceURL  serveResource() method is invoked from UI.

    6. processEvent()

    For implementing IPC (Inter Portlet Communication) this method is used.

    Portlet Mode

     The PortletMode class represents the possible modes that a portlet can assume.

    A portlet mode indicates the function a portlet is performing. Normally, portlets perform different tasks and create different content depending on the function they are currently performing. When invoking a portlet, the portlet container provides the current portlet mode to the portlet.

    Portlets can programmatically change their portlet mode when processing an action request.

    This class defines the default portlet modes EDIT, HELP, VIEW. Additional portlet modes may be defined by calling the constructor of this class. If a portal/portlet-container does not support a custom portlet mode defined in the portlet application deployment descriptor, the custom portlet mode will be ignored by the portal/portlet container.

    So remember there are only 3 portlet mode according to JSR 286 as mentioned above.

    However Liferay supports below 6 custom portlet mode apart from the standard 3 portlet modes

    1. About

    2. Config

    3. Edit Defaults

    4. Edit Guest

    5. Preview

    6. Print

    Window State

     The WindowState class represents the possible window states that a portlet window can assume.

    This class defines a standard set of the most basic portlet window states. Additional window states may be defined by calling the constructor of this class. If a portal/portlet-container does not support a custom window state defined in the portlet application deployment descriptor, the custom window state will be ignored by the portal/portlet container.

    NORMAL : 

    The NORMAL window state indicates that a portlet may be sharing the page with other portlets. It may also indicate that the target device has limited display capabilities. Therefore, a portlet should restrict the size of its rendered output in this window state.

    The string value for this state is "normal".

    MAXIMIZED:

    The MAXIMIZED window state is an indication that a portlet may be the only portlet being rendered in the portal page, or that the portlet has more space compared to other portlets in the portal page. A portlet may generate richer content when its window state is MAXIMIZED.

    The string value for this state is "maximized".

    MINIMIZED:

    When a portlet is in MINIMIZED window state, the portlet should only render minimal output or no output at all.

    The string value for this state is "minimized".

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