7.2 MessageListener
The org.apache.jetspeed.portlet.event.MessageListener interface must be implemented by the portlets receiving a message. The interface defines the single method listed in Example 7-1. Since the portlet may be notified by more than one other portlet and therefore may receive different types of messages, it should validate the type of message received prior to working with the object. This is illustrated in Example 7-1.
Example 7-1 Implementing the MessageListener interface
public void messageReceived(MessageEvent event) throws PortletException {
PortletMessage msg = event.getMessage();
if( msg instanceof DefaultPortletMessage ) { String messageText = ((DefaultPortletMessage)msg).getMessage(); // Add DefaultPortletMessage handler here } ..... }
Be aware that when a portlet receives a message, it is not in Edit or Configure mode and therefore faces certain restrictions. For instance, portlets do not have write access to the PortletData object when they are not in Edit mode. Also, they cannot adjust the attributes stored in the PortletSettings object unless they are in configure mode. Attempts to store attributes in these object when not in the appropriate mode result in an AccessDeniedException.
Therefore, when attempting to share configuration or settings information between portlets, you need to choose your scope carefully or decide to persist to an outside resource.
ibm.com/redbooks
Prev | Next