Monday, October 3, 2011

Inter Portlet Communication (IPC) in Liferay


A common question and topic when I do training or work on support cases, is, "What is the right way to do inter portlet communication in Liferay?"
Well, there is no "right way" to do this. At least not yet. This is because IPC was left out of JSR-168. In other words, there is no standard API. As for JSR-286, there will be a IPC standard that will be an event system. IPC is on the Liferay roadmap as well.
For the time being, here are three ways in which IPC can be implemented:

Method 1) The first is to use the request attributes to pass messages between portlets. You can also use session attributes for this as well.
Method 2) We provide a proprietary portlet url tag that allows you to target one portlet to another (cross-linking). It looks something like this:
<liferay:actionURL portletName="xxx" />
Method 3) Use our AJAX toolkit to inject content from one portlet to another. See http://wiki.liferay.com/index.php/Ajax_Toolkit for more information. You can see how you can use this in conjunction with portlet urls to inject content into a div layer.

The most recommended approach is to use (Method 1) from above, using request or session attributes.

In order for this to work you must have the portlet calling request.setAttribute() and it needs to be doing it within processAction(), so that this executes before the other portlets call render().

Once you do this IPC is complete, the other portlets can pick up the message using renderRequest.getAttribute().

AJAX vs. NON-AJAX
You will have to use a non-ajax approach if you want it to be more flexible. So basically, the trade-off is:
1) non-ajax approach is more flexible
2) ajax approach requires hardcoding of the portlet name in the JSP

What is Liferay ?


Liferay Portal is an enterprise web platform for building business solutions that deliver immediate results and long-term value.

Liferay Portal is a free and open source enterprise portal written in Java.

It is primarily used to power corporate intranets and extranets.Liferay Portal allows users to set up features common to websites. It is fundamentally constructed of functional units called portlets.

Liferay is sometimes described as a content management framework or a web application framework.

Although Liferay offers a sophisticated programming interface for developers, no programming skills are required for basic website installation and administration.

Liferay Portal is Java based and runs on any computing platform capable of running the Java Runtime Environment and an application server. Liferay is available bundled with an application server such as Apache Tomcat.

More at http://www.liferay.com/products/liferay-portal/overview