首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

Liferay中的Portlet事件通讯

2014-01-03 
Liferay中的Portlet事件通信Here below are the steps to follow for IPC :Sender portlet?To configure a

Liferay中的Portlet事件通信



Here below are the steps to follow for IPC :

Sender portlet?To configure a portlet to be available to send events, add the following to your portlet.xml:?First, you have to define the event to send. To do this, you need to specify a namespace and a name for your event.?This definition is the event definition that has to go into the portlet.xml of the sender AND of all receivers.In our case it defines, that an event called "message" for the namespace http:your.private.namespace.com/yourEvent exists which is a String?<event-definition>
<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();
}
}

热点排行