Roufid

Liferay IPC using public render parameters (Portlet communication)

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:

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 :

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

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 :

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

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 :

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