Using Interportlet Communications

Event Generation and Subscription

Event generation starts with an event generated in processAction() method of a portlet. Further events can also be generated in handleEvent() method in portlet class while handling the event received. The handleEvent() method will be called if and only if an event is fired and the portlet has subscribed to listen to that event. The events can also be generated in response to other events in handleEvent() method.

To create portlets which are interested in listening to certain events and taking some action in response to these events, the portlet must implement PortletEventListener interface. This interface has only handleEvent() method. The portlet gets the data from EventRequest and can take appropriate action. The developer can set any information required for the correct rendering of the portlets on EventResponse as render parameters.

All the portlets which are interested in listening or generating an event must declare it in sun-portlet.xml file. If a portlet requests an event which has not been declared in the sun-portlet.xml file, an exception NotRegisteredException will be thrown. Wild cards can not be used for declaring the events that will be generated. However, portlets interested in consuming all the events can use wildcard character (*) only inside <consumes—event></consumes—event> block.