Code Example for Listener Portlet (ipc2)
package com.sun.portal.portlet.ipc2;
import com.sun.portal.portletappengine.ipc.EventNotRegisteredException;
import com.sun.portal.portletappengine.ipc.EventRequest;
import com.sun.portal.portletappengine.ipc.EventResponse;
import com.sun.portal.portletappengine.ipc.PortletEvent;
import com.sun.portal.portletappengine.ipc.PortletEventBroker;
import com.sun.portal.portletappengine.ipc.PortletEventListener;
...
/**
* The DecisionPortlet participates in the InterPortletCommunication.
* This consumes the event generated by the PricePortlet which is in the
* same web application.
* This also generates the event that is consumed by the PricePortlet.
*/
public class DecisionPortlet extends GenericPortlet{
implements PortletEventListener ...
public void handleEvent(EventRequest ereq, EventResponse eres) {
String name = ereq.getEventName();
if (name.equalsIgnoreCase("priceChanged")) {
String data = (String) ereq.getEventData();
int price_data = Integer.parseInt(data);
PortletEventBroker peb = new PortletEventBroker(ereq);
if (price_data > 500) {
try {
PortletEvent pe = peb.createEvent("highPriceEvent");
pe.setEventData(data);
pe.fire();
} catch (EventNotRegisteredException e) {
e.printStackTrace();
}
} else {
try {
PortletEvent pe = peb.createEvent("lowPriceEvent");
pe.setEventData(data);
pe.fire();
} catch (EventNotRegisteredException e) {
e.printStackTrace();
}
}
eres.setRenderParameter("price", data);
} else if (name.equalsIgnoreCase("priceChanged2")) {
eres.setRenderParameter("price2", name);
} else if (name.equalsIgnoreCase("priceChanged3")) {
eres.setRenderParameter("price3", name);
}
}
...
}