« Back to Inter-portlet...

Eventing and Shared Render Parameters

Introduction #

This page documents using Events and Shared Render Parameters to carry out 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.

Environment #

  • IDE - NetBeans 6.7 with Portal Pack 3.0.2.

Shared Render Parameters #

From Portlet

  • FromPortlet_view.jsp: In this portlet page we can the parameter that is sent as public parameter and in this sample has name action-id

To Portlet

  • ToPortlet_view.jsp: In this portlet page we get the parameter and print the value

Common

  • portlet.xml: The most important in the portlet.xml are the following lines:
    • <supported-public-render-parameter>action-id</supported-public-render-parameter>
    • <public-render-parameter><identifier>action-id</identifier><qname xmlns:x="http://www.liferay.com/public-render-parameters">x:action-id</qname></public-render-parameter>

Supported Shared Render Parameters in Liferay #

Several built-in Liferay portlets support various shared render parameters to affect their display. For example, one can create a portlet which contains links which, when clicked, make Liferay's Blogs portlet only show blogs that have been tagged with a certain tag.

PortletSupported ParameterEffect
Asset Publisher
categoryId
Displays assets in the specified category
Asset Publisher
tag
Displays assets tagged with the specified tag
Asset Categories Navigation
categoryId
Sets the "current" category displayed
Asset Tags Navigation
tag
Sets the "current" tag displayed
Asset Tags Cloud
tag
Sets the "current" tag displayed
Document Library
categoryId
Displays documents in the specified category
Document Library
tag
Displays documents tagged with the specified tag
Document Library Display
categoryId
Displays documents in the specified category
Document Library Display
tag
Displays documents tagged with the specified tag
Bookmarks
categoryId
Displays bookmarks in the specified category
Bookmarks
tag
Displays bookmarks tagged with the specified tag
Image Gallery
categoryId
Displays images in the specified category
Image Gallery
tag
Displays images tagged with the specified tag
Blogs
categoryId
Displays blogs in the specified category
Blogs
tag
Displays blogs tagged with the specified tag
Wiki
categoryId
Displays wikis in the specified category
Wiki
tag
Displays wikis tagged with the specified tag
Wiki
nodeId
Displays the specified wiki page identified by nodeId
Wiki
title
Displays wiki page with the specified title

portlet.xml declarations #

As described above, for your portlet to utilize the built-in Liferay parameters, you must declare two things in your portlet.xml:

1. Under

<portlet>
element:

		<supported-public-render-parameter>
			tag
		</supported-public-render-parameter>

2. Under

<portlet-app>
element, one or more of:

	<public-render-parameter>
		<identifier>categoryId</identifier>
		<qname xmlns:x="http://www.liferay.com/public-render-parameters">x:categoryId</qname>
	</public-render-parameter>
	<public-render-parameter>
		<identifier>tag</identifier>
		<qname xmlns:x="http://www.liferay.com/public-render-parameters">x:tag</qname>
	</public-render-parameter>
	<public-render-parameter>
		<identifier>nodeId</identifier>
		<qname xmlns:w="http://www.liferay.com/public-render-parameters/wiki">w:nodeId</qname>
	</public-render-parameter>
	<public-render-parameter>
		<identifier>title</identifier>
		<qname xmlns:w="http://www.liferay.com/public-render-parameters/wiki">w:title</qname>
	</public-render-parameter>

Notice the namespace for

nodeId
and
title
are different than the others (it has a 'wiki' suffix).

Events #

This method of intercommunication is more complex than shared render parameters, but it is more powerful because events can be processed by other portlets.

From Portlet (Publisher) The main line of portlet page is:

  • <form method="post" action="<portlet:actionURL><portlet:param name="javax.portlet.action" value="savecontact" /></portlet:actionURL>">

In the java code of the portlet we have the following main lines:

  • @ProcessAction(name="savecontact")
  • And the method saveContact where we get the parameters and set/trigger the event

In the portlet.xml the main lines are:

  • <supported-publishing-event><qname xmlns:x="http:mycompany.com/events">x:contactInfo</qname></supported-publishing-event>
  • <event-definition><qame xmlns:x="http:mycompany.com/events">x:contactInfo</qname><value-type>java.util.Hashmap</value-type></event-definition>

To Portlet (Listener) The main line of portlet page is:

  • getAttribute
  • Print the values

In the java code of the portlet we have the following main lines:

  • @ProcessEvent(qname="{http:mycompany.com/events}contactInfo")
  • Method processEvent1 where we get the event values and apply business logic

In the portlet.xml the main lines are:

  • <supported-publishing-event><qname xmlns:x="http:mycompany.com/events">x:contactInfo</qname></supported-publishing-event>
  • <event-definition><qame xmlns:x="http:mycompany.com/events">x:contactInfo</qname><value-type>java.util.Hashmap</value-type></event-definition>
7 Attachments
33825 Views
Average (5 Votes)
The average rating is 2.8 stars out of 5.
Comments
Threaded Replies Author Date
Thanks for clarifying! Suraj Bihari November 15, 2011 1:34 PM
Hi, We are using Shared Render Parameters for... Manoj Satyagi April 6, 2012 2:25 AM
Hi Manoj, I am trying... Vasanth Kumar July 11, 2012 3:59 AM
Hey Vasanth, Please find the sample demo... Nagaraj Desingurajan December 12, 2012 1:41 AM
Get the source code from the gievn github link. Nagaraj Desingurajan December 12, 2012 1:42 AM

Thanks for clarifying!
Posted on 11/15/11 1:34 PM.
Hi,
We are using Shared Render Parameters for implementation of IPC between two different portlets. Its working fine in Liferay 6.0.6 CE but the same is not working in Liferay 6.0.6 EE.

Has anyone faced the same issue ? If so kindly provide me a fix for the same.

Regards,
Manoj-GT
Posted on 4/6/12 2:25 AM.
Hi Manoj,

I am trying InterPortletCommunication using event based in Liferay 6.1.0 CE.

Plz find the requirement in the below link:

http://www.liferay.com/community/forums/-/message_boards/message/14782969

Ca­n you plz share portlet code of similar kind of requirement. Also it would be help if your share portlet code which u tried in Liferay 6.0.6 CE.

Appreciate your help !!!
Posted on 7/11/12 3:59 AM.
Hey Vasanth,


Please find the sample demo projects for IPC in below link.

http://www.liferay.com/community/liferay-projects/liferay-faces/demos#jsf2-­ipc-events-customers-portlet
Posted on 12/12/12 1:41 AM in reply to Vasanth Kumar.
Get the source code from the gievn github link.
Posted on 12/12/12 1:42 AM in reply to Nagaraj Desingurajan.