Inter Portlet Communication using portlet messaging

0 comments



This solution is for those who are still using IBM API for portlet development.

Portal developers generally face the difficult task of integrating applications into a common interface. WebSphere Portal provides a framework with built-in support for portlet communication or messaging among portlets in the application.

Here are the basics. One portlet sends the message (the portlet's action listener), and that message is received by one or more portlets in the application (he portlet's message listener). The user performs an action in one portlet; the action event is captured and processed, and the message is relayed to other portlets. A single portlet can both send and receive messages.

Limitations
  • To perform messaging among portlets, those portlets have to be on the same page. This limitation is due to performance issues.
  • If your portlet implements the PortletMessage Interface, portlet messaging must occur within the same portlet application (one or more portlets packaged in the same .WAR file). If your portlets extend the Default PortletMessage interface, they can interact with other portlet applications.
Message Sending Action:
public void actionPerformed(ActionEvent event) throws PortletException {
PortletRequest request = event.getRequest();
String employeeName = request.getParameter("employeeName");
String sendToAllPortlets = request.getParameter("sendToAllPortlets");
String portletName = request.getParameter("portletName").trim();
if ( employeeName != null && employeeName .trim().length() > 0 )
{
DefaultPortletMessage message = new DefaultPortletMessage (employeeName );
if(sendToAllPortlets .equals("yes") )
getPortletConfig().getContext().send(null, message);
else
getPortletConfig().getContext().send(portletName, message);
}
}
Default Portlet Message

The DefaultPortletMessage can be used for inter-portlet communication beyond one portlet application. Therefore this is a final class that can not be further extended. A portlet that broadcasts messages should publish its message object format in its documentation.

Message Receiving Action:

public void messageReceived(MessageEvent event)
{
DefaultPortletMessage message =
(DefaultPortletMessage) event.getMessage();
PortletRequest request = event.getRequest(); request.getSession().setAttribute(EMPLOYEE_NAME,message.getMessage());
}
messageReceived (MessageEvent event)

Notifies this listener that the message which the listener is watching for has been performed.

No comments:

Post a Comment

Recent Posts

Popular Posts

© 2011-2019 Web Portal Club