Inter Portlet Communication (IPC) by Portlet Session in Liferay


Inter Portlet Communication can be done by many ways like by using events,public render parameters and Portlet Session. Today we discuss about IPC by using Portlet Sessions. Here we set some value in one portlet and get value in other Portlet.

We take a simple scenario where user can select food type from one portlet and second portlet shows food items on the basis of first portlet. This is a Sender, Receiver kind of scenario.Here we create two project and each project contain one portlet.

So lets start this step by step:-


For Sender

Step 1:-Create Liferay Project
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as Session_Sender and click finish.

Step 2:-Create MVC Portlet inside project
Right Click on your project ie Session_Sender and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.

Step 3:-Change liferay-portlet.xml
Open liferay-display.xml and set private session attribute to false so that attribute set in session available to different wars:-

<private-session-attributes>false</private-session-attributes>

Also we are not using AUI so set required namespace parameter to false:-

<requires-namespaced-parameters>
                    false
</requires-namespaced-parameters>

Now your liferay-portlet.xml become:-



Step 4:-Change view.jsp
Open view.jsp and paste this content:-


Explanation:-
Creating a simple form with two radio button on the submittion of form processFood method is called.


Step 5:-Change the Controller
Open your java class and paste this:-


Explanation:-
Here we fetch the value from form and set in Session Object with Application Scope so that it is available to whole application.We have one more Scope called Portlet scope.






For Receiver

Step 1:-Create Liferay Project
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as Session_Receiver and click finish.

Step 2:-Create MVC Portlet inside project
Right Click on your project ie Session_Sender and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.

Step 3:-Change liferay-portlet.xml
Open liferay-display.xml and set private session attribute to false as in Sender.

Step 4:-Change your Controller
Open your java class and paste this:-


Explanation:-
Here we fetch the value from session that is set by the Sender and again set in renderRequest so that it is available in view.jsp.


Step 5:-Change view.jsp
Open view.jsp of receiver as:-


Explanation:-
Here we get the value that is set in Controller and on the basis of condition show different messages.

Note:- We are using jstl tage here so provide entry in liferay-plugin-package.property file as:-





For Output


Now deploy both sender and receiver portlet and add to same page or different page. I am adding Sender on one page and Receiver on other.

Here i am adding Sender on Welcome page and select Vegetarian and click Submit:-


The Receiver Portlet is on about page:-



Now again go to and select Non- Vegetarian and click submit and see the Receiver as:-