portlet2.0 的通信特性
JSR268中定义了portlet之间的通信协议
基本的原理就是事件监听机制,portlet A 触发事件。portlet B对时间进行监听并作出反应。传递的数据放在 事件的 payload 里面。并且事件通信的两个portlet可以不再同一个page,需要修改portlet.event.distribution=layout。 具体参见liferay in action 里 ipc 那一章。
下面展示通过liferay in action 的一个例子。
pitchPortlet view.jsp 上有一个 按钮。通过该按钮 该portlet发送一个事件。
catcherPorlet 写好时间监听函数。
step 1. 创建 pitchPortlet.(使用liferay官方下载的eclipse,已经集成好liferay)
a. 修改portlet.xml
<event-definition>
<qname xmlns:x="http://liferay.com/events">x:ipc.pitch</qname>
<value-type>java.lang.String</value-type>
</event-definition>
声明 portlet 事件。
b. 定义事件发生者(在pitchPortlet 的xml定义)
<supported-publishing-event>
<qname xmlns:x="http://liferay.com/events">x:ipc.pitch</qname>
</supported-publishing-event>
c. 定义事件处理者 (在 catchPortlet 的xml定义)
<supported-processing-event>
<qname xmlns:x="http://liferay.com/events">x:ipc.pitch</qname>
</supported-processing-event>
d.完整的xml定义:见附件
e.完成 PitcherPortlet
@ProcessAction(name="pitchBall")
public void pitchBall(ActionRequest actionRequest, ActionResponse actionResponse)throws IOException, PortletException {
//其他逻辑
//qname 与事件定义时一直
QName qName = new QName ("http://liferay.com/events", "ipc.pitch");
actionResponse.setEvent(qName, pitchType);
}
f.完成catchPortlet
@ProcessEvent(qname="{http://liferay.com/events}ipc.pitch")
public void catchBall(EventRequest request, EventResponse response) {
Event event = request.getEvent();
String pitch = (String)event.getValue();
response.setRenderParameter("pitch", pitch);
}
g. pitchPortlet /view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<p>Click the link below to pitch the ball. </p>
<portlet:actionURL var="pitch" name="pitchBall"></portlet:actionURL>
<a href="<%=pitch%>">Pitch!</a>
h. catchPortlet /view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<%
String pitch = (String)renderRequest.getParameter("pitch");
%>
<p>And the pitch is....</p>
<p>
<% if (pitch!=null) { %>
<%=pitch %>!
<% } else { %>
... waiting for pitch.
<% } %>
I :部署运行 点击pitch 就可以看到 catchPortlet 的反应
分享到:
相关推荐
liferay跨组件间通信实例
liferay portlet demo
liferay_Struts2_Demo开发
liferay hook 开发demo,swf格式
liferay struts2 demo
liferay-demo:Liferay示范
liferay hook 开发demo 2,swf格式
使用liferay框开发ajax 的Demo
一个简单的学习liferay例子,结合struts2做个一个demo,有不对的地方,还请多多指教。
Liferay开发实战(2):Service Builder生成持久化层,一个简单留言板的例子。 http://www.cnblogs.com/starcrm/p/5175674.html
Liferay Portal Liferay IDE
Liferay中的AUI框架,官方叫做Alloy,是一个UI超框架,能为浏览器的三方面,结构,风格和表现建立网络应用提供连续的简单的API。 它融合了三种设计语言:HTML, CSS 和 JAVA。 准确来说AUI是Liferay在YUI的基础上...
详细的说明了portlet的开发步骤以及有代码例子,希望能帮助大家。
liferay portal 开发指南liferay portal 开发指南liferay portal 开发指南liferay portal 开发指南
打开Liferay IDE,Window-->Preferences-->Server-->Runtime Environment,点击右边Add…,在弹出的服务器选择里面选择Liferay,Inc-->Liferay v6.1 CE (Tomcat 7),请打“Create a new location server”打上勾。...
Liferay Themes[1].pdf Liferay+CMS系统培训.ppt Liferay+Portal+数据库介绍+.doc Liferay+权限管理.doc liferay-portal-5-2-systems-development-sample-chapter-5-managing-pages[1].pdf ...
liferay 超级学习文档 liferay 框架 java hibernate liferay 不用多说
Liferay演示模块 该存储库包含各种Liferay OSGi模块,用于演示。
Liferay is a different portal. 10分下载的, 打包5折提供下载. Part 1 Introduction to Liferay 1. Liferay is a different portal 2. Getting started with the Liferay development platform Part 2 Adding ...