Liferay中的Portlet事件通信
Here below are the steps to follow for IPC :
<qname xmlns:t="http:your.private.namespace.com/yourEvent">t:message</qname>
<value-type>java.lang.String</value-type>
</event-definition>?To choose your portlet as a sending portlet additionally add the following:?<supported-publishing-event>
?? <qname xmlns:u="http:your.private.namespace.com/yourEvent">t:message</qname>
</supported-publishing-event>?This selects your portlet as a sending portlet for the chosen event. This is all for the configuration of the sender portlet.?Now let′s write code to send an event in sender class.?public void sendEvent(ActionRequest actionRequest,ActionResponse actionResponse) {
QName qname = new QName(“http:your.private.namespace.com/yourEvent","message");
actionResponse.setEvent(qname,"Hello World");
return;
} ??Receiver portlet?First add the event definition to the portlet.xml of your receiving portlet.?<event-definition>
<qname xmlns:t="http:your.private.namespace.com/yourEvent">t:message</qname>
<value-type>java.lang.String</value-type>
</event-definition>?Second, add tis code to process an event?<supported-processing-event>
<qname xmlns:u="http:your.private.namespace.com/yourEvent">t:message</qname>
</supported-processing-event>?Now, just write code to your receiving portlet class, ?@Override
public void processEvent(EventRequest request, EventResponse response) {
Event event = request.getEvent();
if (event.getName().equals("message")) {
String ?message = (String) event.getValue();
}
}