« Development に戻る

Inter-portlet communication

Introduction #

The first version of the portlet specification, JSR-168, did not include any support for Inter Portlet Communication. The second version, JSR-286, which is supported by Liferay since version 5 does. This page describes a series of methods that can be used to communicate portlets prior to that version, or that you might prefer to use even after that version. It also includes links to articles with information about the mechanisms introduced in JSR-286.

Standard IPC introduced in JSR-286 (Portlets 2.0) #

JSR-286 introduces two methods of Inter Portlet Communication:

  • Shared render parameters: allows portlets to set params that can be read by other portlets. This rather simple mechanism will probably be enough for all but the most complex communication needs.
  • Events: needed for complex scenarios. The main advantage of this second method is that it allows a fully decoupled communication. A portlet issues an event and doesn't have to care if there is anyone listening for it.

A more detailed description about these two methods an other new features of Portlets 2.0 can be read in What's new in the Java Portlet Specification V2.0 (JSR 286)?.

|The Client side events mechanism #

This is a new mechanism introduced in Liferay v5.0 and provides a very lightweight and decoupled mechanism to communicate portlets purely in the browser through a JavaScript events mechanism.

A full wiki article covers this topic in detail: Client-side Inter-Portlet Communication]

AJAX way#

The pattern is:

You make an ajax call from one portlet and provide this portlet with id in another portlet. When you have an answer from the ajax call you update the div with the information you got.

It would be convenient to route the calls through a container object. Whenever, a portlet is added or removed, it needs to register/un-register itself to the container. The container would refer to the portlet through it's id and the reference to the DIV element.

Session variables sharing #

Another way is to store variables in the session and make them sharable for portlets. This way you can put stuff into session and display different things based on the information in the session. Look here: Sharing session variables

Use Liferay portlet url tag #

Proprietary portlet url tag that allows you to target one portlet to another (cross-linking). It looks something like this

  <liferay-portlet:actionURL portletName="xxx" />

Where "xxx" is the <portlet-name>xxx</portlet-name> of the portlet as defined in the portlet.xml file.

Note that it also needs to include the WAR reference if it is in a portlet war.

e.g. A war named "sample-struts-liferay-portlet" having a portlet with the name "sample_struts_liferay_portlet" will have an fully qualified name as:

  sample_struts_liferay_portlet_WAR_samplestrutsliferayportlet

Furthermore, if the portlet is instanceable (<instanceable>true</instanceable> in liferay-portlet.xml) it will contain an instance identifier like so:

  _INSTANCE_im3I

making the full name:

  sample_struts_liferay_portlet_WAR_samplestrutsliferayportlet_INSTANCE_im3I

The end result is a portlet tag like so:

  <liferay-portlet:actionURL portletName="sample_struts_liferay_portlet_WAR_samplestrutsliferayportlet_INSTANCE_im3I" />

You can also look at this topic for discussion and details: http://www.liferay.com/web/guest/community/forums/message_boards/message/272753

0 添付ファイル
124851 参照数
平均 (1 投票)
平均評価は3.0星中の5です。
コメント
コメント 作成者 日時
bump Andre Darian Bonner 2008/10/14 13:55
The information about Inter Portlet... Carlos Santos 2009/11/10 4:18
Could someone elaborate on this more? I am... J B 2010/04/09 12:31
Help! I need a real sample.. Which files I need... Melvin Rodriguez Rojas 2011/03/30 10:44
can someone send to harokidz@gmail.com sample... Pieter Haro 2011/07/18 20:51
http://liferaycms.blogspot.com/2011/07/inter-po... Jignesh Vachhani 2011/08/19 0:20

The information about Inter Portlet Communication feature of the 2.0 portlet spec could be more explicit.
投稿日時:09/11/10 4:18
Could someone elaborate on this more? I am trying to utilize this using ColdFusion 9 portlets under JBOSS Liferay. And I am starting to pull out hair at this point...

How does a <liferay-portlet:actionURL portletName="sample_struts_liferay_portlet_WAR_samplestrutsliferayportlet_INSTAN­CE_im3I" /> tag help me pass info from one to the other?
投稿日時:10/04/09 12:31
Help! I need a real sample..
Which files I need to edit.???
portlet.xml??

In portlet 1 how I make the link to call portlet 2..
and in portlet 2 how I capture the call from the portlet 1 ..
Thaks!
投稿日時:11/03/30 10:44
can someone send to harokidz@gmail.com sample how to communicate 2 portlet
投稿日時:11/07/18 20:51
http://liferaycms.blogspot.com/2011/07/inter-portlet-communication.html
Pieter Haroへのコメント。投稿日時:11/08/19 0:20