7.4 DefaultPortletMessage
This object implements the PortletMessage interface and provides the basic functionality needed for sending string messages between portlets on the same page regardless of the portlet application.
Note: Since portlet messaging can be accomplished across portlets in different applications, this is the recommended way to implement portlet messaging.
If you broadcast a DefaultPortletMessage to null, it will be sent to all portlets on the page implementing the MessageListener interface. Example 7-2 illustrates sending a simple broadcast message to all portlets on the same page regardless of application affiliation.
Example 7-2 Broadcasting a message to all portlets on a page
PortletMessage msg = new DefaultPortletMessage("Some Message"); getPortletConfig().getContext().send(null, msg);
![]()
If you specify the portlet name, the message will be sent to all portlets and all their instances on the same page. The portlets with that name receive the message if they have implemented the appropriate listener. If the source and target portlet have the same name, the message will not be sent to avoid cyclic calls.
Example 7-3 Sending a message to a given portlet name on a page
PortletMessage msg = new DefaultPortletMessage("Some Message"); getPortletConfig().getContext().send("Portlet name", msg);
![]()
ibm.com/redbooks
Prev | Next