7.2 MessageListener

 <  Day Day Up  >  

The org.apache.jetspeed.portlet.event.MessageListener interface must be implemented by the portlets you want the portal server to send messages to. The interface defines the single method listed in Example 7-1 on page 227. 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 on page 227.

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.

 <  Day Day Up  >  


IBM WebSphere Portal V5 A Guide for Portlet Application Development
IBM Websphere Portal V5: A Guide for Portlet Application Development
ISBN: 0738498513
EAN: 2147483647
Year: 2004
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net