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

 

Remember, there is no standard or API yet, so we can only give hints on how to implement!

 

Blogs
Hi,
Thanks for providing this information on IPC in Liferay. I've noticed that JSR-286 has been approved by the Java Community Process in July 2007 (see http://blogs.sun.com/portal/entry/jsr_286_public_review), together with a reference implementation. I suppose you are already working on bringing this standard to Liferay... By when can we expect Liferay to support the new standard?

Moreover, since we need a solution for IPC now, what do you recommend for encapsulating inter-portlet communication so that migration towards JSR-286 IPC is as smooth and easy as possible, once the new standard is supported in Liferay?

Cheers,
Konrad
Hi Konrad, Liferay is very tightly connected to JSR 286 and it's been on our roadmap for a while. We're already working on a release for that and all I can really say is that you will not have to wait too long for compliance.

As for IPC, I can't really suggest a good way to encapsulate. The new spec for IPC will be event-driven which is pretty different from the methods described above.
Thanks James,

Question: can we create URL from one portlet to another portlet instance on another _page_? For instance, Journal Content portlet uses <liferay-portlet:renderURL> in many places (to edit article, to select article, etc.), but always with WindowState.MAXIMIZED, and placed on the same page.

Do we have "page" (layout) parameter for <liferay-portlet:renderURL>? Can Liferay automatically determine parent layout using unique portletId?

What is difference between <liferay-portlet:renderURL> and <liferay-portlet:actionURL>?

Thanks
Method 1 (using request attributes) is really the best: we can pass parameters even to Journal Article portlet (Velocity Template, XSLT)
http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Journal+Internal+API

request.setAttribute("test","Just a Test!");
#set ($test = $request.get('attributes').get('test'))

renderURL can automate Friendly-URL construction.
of course Article will be cached, but I need to build dynamically static ;) links inside article - and $request does it (caching even helps)
hii ronald,
I am very new to the Liferay portal development.

I need to implement the Inter Portlet Communication example....
I am using Liferay5.2.3 with Tomcat 6.0.18.
can u pls send any sample code to meet this target..
thank u

sasikala
For JSR-286 (Liferay 5.X), IPC has been standardized to an event-based model. Sun has an example Liferay portlet:

https://lportal.svn.sourceforge.net/svnroot/lportal/plugins/trunk/portlets/sun-tour-ipc-portlet/
Due to my IPC frustration, I am opening this up to ANYONE who has gotten this to work.

I will pay $350 to anyone who can provide me a working example with source code of:

1.) Two portlets, each in their OWN war file, each in their own eclipse project, each containing a single 2.0 portlet using Icefaces 2.0 JSF portlet technology. (not 1.2)
2.) Portlet "A" would have a single text box and command button that when pushed would show what was typed over in Portlet "B". The screen would NOT redraw as Icefaces would use its ajax push technology.
3.) The communication mechanism is the event based mechanism described in this posting using "event-definition" type configuration.
4.) Annotations should not be used.
5.) Liferay is the obvious and only choice for the portal technology.

Please respond to chicagomark71@yahoo.com. Money paid via paypal. Your first deliverable would be the two war files themselves that I could test. First come first served, I only pay out to the person who solves this first.
The book "JavaServer Faces 2.0, The Complete Reference" has an appendix on JSF in Liferay, and there is a section on Inter-Portlet Communication.

There is some information on what JSF portlet bridges support Public Render Parameters, and what versions might support Server-Side events (a fairly recent development).

There is no complete WAR there, but there is sample code, and a possible explanation on why perhaps the bridge (or version of) you are using may not be working. The section is written by Neil Griffin, a JSF expert who works on the ICEFaces project and Liferay.
hi i am working with liferay 6 . i want to use ajax in interportlet communication please help in finding an example..