`

Liferay中的Portlet事件通信

 
阅读更多

Liferay中的Portlet事件通信在有的项目开发中是需要实现的一种机制。

下面转自http://liferaycms.blogspot.com/2011/07/inter-portlet-communication.html

Inter portlet communication

Here is the flow of IPC



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();
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics