How to send and recieve events in JSR 286 portlets?


One of the important features of JSR 286 API is the ability to send and receive events from one portlet to another. From events we mean, enabling a portlet to send and receive events and perform state changes or send further events as a result of processing an event. Following configuration and code changes are required to support events in Portlets.

The portlet from where we have to set the object and publish it. Make the following configuration changes in portlet.xml file.

<portlet-app .....>
         <qname xmlns:x="http:com.example/events">x:Address</qname>

        <qname xmlns:x="http:com.example/events" >x:Address</qname>

For publishing we have set the object in processAction. Make the following changes in the portlet class of source portlet.

public void processAction (ActionRequest request, ActionResponse response) throws PortletException,IOException {
        QName qname = new QName("http:com.example/events" , "Address");
        String value = request.getParameter("personName");
        Address address= new Address ();
        response.setEvent(qname, address);

The portlet from where we have to get the object and process it.

<portlet-app ...>
       <qname xmlns:x="http:com.example/events">x:Address</qname>

Java code to get the object value in our portlet API

public void processEvent(EventRequest request, EventResponse response) {
Event event = request.getEvent();
     if(event.getName().equals("Address")) {
       Address address= (Address)event.getValue();
       response.setRenderParameter("address", payload.getName());

public class Address implements Serializable {

private String name;
private String address;

public String getName() {
return name;
public void setName(String name) { = name;
public String getAddress() {
return address;
public void setAddress(String address) {
this.address= address;

No comments:

Post a Comment

Recent Posts

Popular Posts

© 2011-2019 Web Portal Club