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();
}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值