IBM Portlet allows to methods for 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.
I have created some portlets that implement both methods of communication and going to try to share the main points to communicate portlets using these methods.
IDE
- The first thing to point is that the development IDE I am using is 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
- ToPortlet_view.jsp: In this portlet page we get the parameter and print the value
- 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>
Events
This method of intercommunication is much more complex than shared render parameters but looks much more power full that shared render parameters method because the event can be processed by other portlet and I think this functionality is very interesting.
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>
0 comments:
Post a Comment