portlet.xml
<?xml version="1.0" encoding="UTF-8"?> <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"> ... <portlet> ... <supported-processing-event> <name>add-person</name> </supported-processing-event> <supported-publishing-event> <name>add-person</name> </supported-publishing-event> </portlet> ... <event-definition> <name>add-person</name> <value-type>org.jasig.census.Person</value-type> </event-definition> </portlet-app>
pom.xml
... <dependency> <groupId>javax.portlet</groupId> <artifactId>portlet-api</artifactId> <version>2.0</version> <type>jar</type> <scope>provided</scope> </dependency> ...
CensusCollectPortlet.java
... people.put(ssn, person); response.setEvent("add-person", person); ... @Override public void processEvent(EventRequest request, EventResponse response) { Event event = request.getEvent(); String eventName = event.getName(); Person payload = (Person)event.getValue(); System.out.println("CensusCollect Received Event: name=" + eventName + ", value=" + payload); } ...
CensusViewPortlet.java
... @SuppressWarnings("unchecked") @Override public void processEvent(EventRequest request, EventResponse response) { Event event = request.getEvent(); String eventName = event.getName(); Person payload = (Person)event.getValue(); System.out.println("CensusView Received Event: name=" + eventName + ", value=" + payload); PortletSession session = request.getPortletSession(true); Map<String,Person> people = (Map<String,Person>)session.getAttribute(PEOPLE); if (people != null) { people.put(payload.getName(), payload); } } ...