« Back

Inter Portlet Communication (IPC) in Liferay

Company Blogs November 2, 2007 By James Min Staff

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!

 

Threaded Replies Author Date
Hi, Thanks for providing this information on... Konrad Wulf November 12, 2007 4:42 AM
Hi Konrad, Liferay is very tightly connected to... James Min November 20, 2007 4:36 PM
Thanks James, Question: can we create URL from... Fuad Efendi July 25, 2008 10:59 AM
Method 1 (using request attributes) is really... Fuad Efendi July 25, 2008 12:03 PM
of course Article will be cached, but I need to... Fuad Efendi July 25, 2008 12:08 PM
hii ronald, I am very new to the Liferay portal... sasi kala February 26, 2010 4:41 AM
For JSR-286 (Liferay 5.X), IPC has been... James Min February 26, 2010 10:07 AM
Due to my IPC frustration, I am opening this up... Mark Ricard September 27, 2010 1:00 PM
The book "JavaServer Faces 2.0, The Complete... James Min September 27, 2010 1:12 PM
[...] Hi, Mostly for IPC better to keep both... Anonymous July 10, 2012 4:58 AM
hi i am working with liferay 6 . i want to use... krishna mohan mathakala September 7, 2012 10:37 PM
[...] 1)      What are the various ways in... Anonymous July 17, 2014 10:30 PM

Konrad Wulf
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
Posted on 11/12/07 4:42 AM.
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.
Posted on 11/20/07 4:36 PM in reply to Konrad Wulf.
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
Posted on 7/25/08 10:59 AM.
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+Interna­l+API

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

renderURL can automate Friendly-URL construction.
Posted on 7/25/08 12:03 PM.
of course Article will be cached, but I need to build dynamically static ;) links inside article - and $request does it (caching even helps)
Posted on 7/25/08 12:08 PM in reply to Fuad Efendi.
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
Posted on 2/26/10 4:41 AM in reply to Fuad Efendi.
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/portle­ts/sun-tour-ipc-portlet/
Posted on 2/26/10 10:07 AM in reply to sasi kala.
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.
Posted on 9/27/10 1:00 PM.
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.
Posted on 9/27/10 1:12 PM in reply to Mark Ricard.
[...] Hi, Mostly for IPC better to keep both portlet on same Page. For IPC implementation : http://www.liferay.com/community/wiki/-/wiki/Main/Inter-portlet+communication...­ [...] Read More
Posted on 7/10/12 4:58 AM.
hi i am working with liferay 6 . i want to use ajax in interportlet communication please help in finding an example..
Posted on 9/7/12 10:37 PM.
[...] 1)      What are the various ways in which you can customize the default behavior of Liferay that ships to you? Ans) One can customize Liferay by writing: Portlets Themes Layout Templates Webs... [...] Read More
Posted on 7/17/14 10:30 PM.