08-10-04 10:58 PM
I am trying to brodcast a message as a DefaultMessage so the portlet which i
s in another application can receive the same. Portlets which are in the sam
e page are able to receive the message but not in the other application.Tryi
ng to run example in Chapte
r 7 in Portla documentation. Code looks like this.
//Sending the message
public void actionPerformed(ActionEvent event) throws PortletException {
;
if( getPortletLog().isDebugEnabled() )
getPortletLog().debug("ActionListener - actionPerformed called");
// ActionEvent handler
String actionString = event.getActionString();
// Add action string handler here
if(actionString.equalsIgnoreCase(ACTION_RED)){
// Create the string of HTML to be rendered
String value = "Action <FONT color=\"#ff0000\">RED</FONT>";
// Create a portlet request
PortletRequest request = event.getRequest();
// Create an instance of portlet data to store values
PortletData portData = request.getData();
try{
// Save value into portlet data
portData.setAttribute("value", value);
portData.store();
}
catch (AccessDeniedException ade){
}catch (IOException ioe){}
// Send a portlet message
PortletMessage message = new DefaultPortletMessage(value);
try{
this.getPortletConfig().getContext().send(null,message);
}catch (AccessDeniedException e){}
}
}
//In receiving portlet which is in another application(Both applications are
in same DefaultEar).
public void messageReceived(MessageEvent event) throws PortletException
3;
if( getPortletLog().isDebugEnabled() )
getPortletLog().debug("MessageListener - messageReceived called");
// MessageEvent handler
PortletMessage msg = event.getMessage();
// Add PortletMessage handler here
if( msg instanceof DefaultPortletMessage ) {
String messageText = ((DefaultPortletMessage)msg).getMessage();
// Add DefaultPortletMessage handler here
PortletRequest request = event.getRequest();
request.setAttribute("message", messageText);
}
else {
// Add general PortletMessage handler here
}
}
If I put this code in a portlet which runs in same application..then it work
s. Have any idea ?
Thanks.
Sudhakar
[ Post a follow-up to this message ]
|