两个portlet分别为sendportlet(发送)和receiveportlet(接收)
1.两个portlet要在portlet.xml文件中进行如下相同的配置:
<default-namespace>http://localhost:8080/FlowData</default-namespace>
<event-definition>
<name>flow-data</name>
<value-type>java.lang.String</value-type>
</event-definition>
2.在sendportlet(发送)的portlet.xml的<portlet></portlet>标签内加上如下配置:
<supported-publishing-event>
<name>flow-data</name>
</supported-publishing-event>
3.在receiveportlet(接收)的portlet.xml的<portlet></portlet>标签内加上如下配置:
<supported-processing-event>
<name>flow-data</name>
</supported-processing-event>
4.在sendportlet(发送)的portlet的processAction方法中使用如下代码发送消息
actionResponse.setEvent("flow-data", "你要传的参数");
5.在receiveportlet(接收)的portlet中,增加方法:
@EventMapping
public void processEvent(EventRequest eventRequest, EventResponse arg1)
throws PortletException, IOException {
Event event = eventRequest.getEvent();
String value = (String) event.getValue();
System.out.println("----"+value);
super.processEvent(eventRequest, arg1);
}
当sendportlet执行完processAction方法后,receiveportlet会马上调用processEvent方法,value就是接收到的参数。