Introduction

Once a portlet is placed on a portal page, its data is not directly shared with other portlets. IPC (Inter Portlet Communication) defines the ways that a Portlet can interact and communicate with another Portlet. There are four ways to make inter portlet communication :

This post will show how to operate a Portlet communication using Public Render Parameters.

Public Render Parameters

Public Render Parameters was introduced in JSR 286 (Portlet 2.0) and aims to pass data from a portlet to another. Below the steps to use public render parameters:

  • Define the public render parameter in the portlet.xml

    Declare the public render parameter in the Portlet.xml file. A public render parameter must have a unique identifier in a given namespace

  • Configure portlets to use the public render parameter in the portlet.xml

    All portlets that want to handle the public render parameter must declare in their Portlet.xml the property <supported-public-render-parameter> that refers to the public render parameter id.

  • Storing Data in the sender portlet

    Set the renderParameter in the processAction portlet phase

  • Retrieving the stored data in the receiver portlet

    Get the renderParameter from the renderRequest

  • Removing the public render parameter

    Public render parameter can only be removed in processAction phase

The portal stores all public render parameters that are merged with regular parameters set in render URLs or on an ActionResponse.

Concrete example

Let’s see a full example of using the IPC with public render parameter.


The code source is available on Github. Download the source

Let’s consider two portlets :

  • CarList (Sender portlet): This portlet shows a list of cars. The user can select a car from the list. When the user select a car, the car’s id is stored as a public render parameter. The car information will be displayed in the second portlet.
  • CarInformation  (Receiver portlet): If a car is selected (Id stored in the public render parameter), this portlet will display the car information.

IPC using Portlet public render parameter

Defining the public render parameter

First step is to define the public render parameter in which the car identifier will be stored in the portlet.xml file. If the portlets that handle the public render parameter are in the same Liferay Plugin Project, only one definition of the public render parameter must be in the portlet.xml file. If not, each Liferay plugin must declare it in its portlet.xml file.

In this example, the two portlets are in the same Liferay Plugin Project.

The identifier given to the public render parameter is “carId“. The declaration is as following :

Sender portlet : CarList

  • Portlet.xml

Defining the CarList portlet in the portlet.xml file. This portlet must support the defined public render parameter. It must define the <supported-public-render-parameter> property :

  • Selecting the car

In the jsp view, I used an actionURL to process a portlet action in which the public render parameter is setted. Below the code :

The public render parameter is setted in the selectCarAction, as below :

The public render parameter is setted in the actionReponse. Let’s see now how it’s processed in the receiver portlet.

Receiver portlet : CarInformation

  • Portlet.xml

Defining the CarInformation portlet in the portlet.xml file. This portlet must support the defined public render parameter. It must define the <supported-public-render-parameter> property :

  • Getting the carId from the portlet parameters

Retrieving the data from the portlet parameters.

The public render parameter is getted from the renderRequest.

Rendering after deployment

The CarList portlet is on the left. CarInformation portlet is on the right.

Liferay inter portlet communication using event

Below the result after selecting BMW.

Liferay inter portlet communication using event after selecting BMW


The code source is available on Github. Download the source