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>
<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>
<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;
}
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>
<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>
<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)
public void processEvent(EventRequest request, EventResponse response)
{
Event event = request.getEvent();
if (event.getName().equals("message"))
Event event = request.getEvent();
if (event.getName().equals("message"))
{
String message = (String) event.getValue();
}
}
String message = (String) event.getValue();
}
}
相关推荐
详解portlet技术,是帮助你学习进步的好助手哦。快来下载吧
Liferay-Portlet-SDK 5.2.3操作说明.ppt
liferay-portlet-development
一个Liferay Soy Portlet使用web service进行可视化数据的实例。
liferay portlet 开发的例子介绍
liferay portlet例子 liferay portlet例子
中文英文的liferay-portlet-development-guide;主要是里面有中文翻译好的,免去你翻译的烦恼。
可供参考的liferay开发的portlet示例工程,学习参考的简单示例
Liferay5.2.3的样例,通过war.bat打包后发布到相应的liferay环境即可。 另外,需要配置context,tomcat中的代码如下: </Context>
Portlet之间的通信--- Liferay 内部Portlet通信-Liferay中的示例Portlet 示例:从Portlet A输入标题,并使用Portlet B在同一页面上显示标题。
liferay portlet demo
Liferay Portlet 开发文档, 比较全的开发介绍,了解PORTLET 的应用和基本开发, 熟悉Lifery IDE 开发。
Liferay Spring Portlet MVC 使用 Maven 的 Liferay Spring Portlet MVC 项目模板。 Liferay EE 6.2.10.11 (GA1, SP710) Java 1.7 小门户 2.0 弹簧框架 4.1.5 基于注解的控制器配置 用法 $ git clone ...
liferay portlet开发参考手册——作者:温兵
commons-configuration-gae.zip,配置的实现(由apache commons配置库提供),使用google app engine datastore api存储配置参数;配置的实现(由apache commons配置库提供),使用google app engine datastore api...
liferay portlet开发介绍文档。
liferay跨组件间通信实例
Liferay跨页面Portlet之间的调用与数据传递,Portlet之间的通信方法有多种,比如PortletSession,Public Render Parameter,Portlet event等。但是这些方法使用起来都很复杂,像Public Render Parameter和event等,...
Liferay用户导入Portlet 用于从csv文件将用户导入Liferay的Portlet 作为此应用程序的用户数据源,我们将使用具有以下格式的CSV文件: username;email;firstName;lastName;password;male paul;paul@paul.com;Paul...
liferay_4_portlet