
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.
Portlet | Supported Parameter | Effect | |
---|---|---|---|
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
nodeIdand
titleare 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>