« 返回到 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 附件
124853 查看
平均 (1 投票)
满分为 5,平均得分为 3.0。
评论
讨论主题回复 作者 日期
bump Andre Darian Bonner 2008年10月14日 下午1:55
The information about Inter Portlet... Carlos Santos 2009年11月10日 上午4:18
Could someone elaborate on this more? I am... J B 2010年4月9日 下午12:31
Help! I need a real sample.. Which files I need... Melvin Rodriguez Rojas 2011年3月30日 上午10:44
can someone send to harokidz@gmail.com sample... Pieter Haro 2011年7月18日 下午8:51
http://liferaycms.blogspot.com/2011/07/inter-po... Jignesh Vachhani 2011年8月19日 上午12:20

在 08-10-14 下午1:55 发帖。
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-4-9 下午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-3-30 上午10:44 发帖。
can someone send to harokidz@gmail.com sample how to communicate 2 portlet
在 11-7-18 下午8:51 发帖。
http://liferaycms.blogspot.com/2011/07/inter-portlet-communication.html
在 11-8-19 上午12:20 发帖以回复 Pieter Haro