Portlet 通信(四) 利用事件传递参数
来源:互联网 发布:手机调音量软件 编辑:程序博客网 时间:2024/06/06 10:51
利用事件传递参数可以是对象也可以是基本类型
四个步骤:
1):在portlet.xml中定义事件(qname或者name都可以)
<!-- 使用事件传递参数 qname--><event-definition><qname xmlns:x="http://www.wq.com">x:event</qname><!-- 数据类型 --><value-type>entity.Emp</value-type></event-definition>
2):在portlet.xml中发布事件和接收事件
<!-- 发布事件 --><supported-publishing-event><qname xmlns:x="http://www.wq.com">x:event</qname></supported-publishing-event>
<!-- 接收事件 --><supported-processing-event><qname xmlns:x="http://www.wq.com">x:event</qname></supported-processing-event>
3):在一个portlet中接收事件,在另一个portlet中接收事件
案例:G向H利用事件传递参数 分别使用qname和name
====================================================================
portletG
package com.test;import java.io.IOException;import java.util.Date;import javax.portlet.ActionRequest;import javax.portlet.ActionResponse;import javax.portlet.PortletException;import javax.portlet.ProcessAction;import javax.xml.namespace.QName;import com.liferay.util.bridges.mvc.MVCPortlet;import entity.Emp;/** * 通过事件传递参数 */public class TranG extends MVCPortlet { @ProcessAction(name="send4")public void ww(ActionRequest request,ActionResponse response) throws IOException, PortletException {Emp emp = new Emp();emp.setName("丹丹");emp.setAge(10);emp.setTime(new Date());//发布事件qnameQName qname = new QName("http://www.wq.com", "event");response.setEvent(qname, emp);//发布事件name--传递字符串response.setEvent("event2", "Hello World");}}
JSP
<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %><portlet:defineObjects /><portlet:actionURL var="from" name="send4"></portlet:actionURL><html> <body> <form action="<%=from%>" method="post"> <input type="submit" value="提交"/> </form> </body></html>
PortletH
package com.test;import javax.portlet.Event;import javax.portlet.EventRequest;import javax.portlet.EventResponse;import javax.portlet.ProcessEvent;import com.liferay.util.bridges.mvc.MVCPortlet;import entity.Emp;/** * Portlet implementation class TranH */public class TranH extends MVCPortlet {@ProcessEvent(qname="{http://www.wq.com}event")public void testEvent(EventRequest request,EventResponse response){//接收事件Event e = request.getEvent();Emp emp = (Emp) e.getValue();System.out.println(emp.getName()+":"+emp.getAge()+":"+emp.getTime());}@ProcessEvent(name="event2")public void testEvent2(EventRequest request,EventResponse response){//接收事件Event e = request.getEvent();String str = (String) e.getValue();System.out.println(str);}}
JSP
<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %><portlet:defineObjects />
---------------------------------------------------------------------------------------------------------------------
点击提交按钮后,传递到指定Portlet(带有事件定义的qname和name方法中)
案例中,PortletH的两个方法中获取到了两次事件传递过来的参数,互不影响
输出结果如下:
丹丹:10:Sun Oct 08 16:46:01 GMT+08:00 2017
Hello World
阅读全文
0 0
- Portlet 通信(四) 利用事件传递参数
- Portlet 通信(五) 通过 URL 传递参数
- Android中的Http通信(四)Post、Get传递参数
- Liferay中的Portlet事件通信
- Liferay Portal(五)各Portlet之间传递参数
- Portlet 通信(一) Portlet Session
- Portlet 通信(二) Portlet URL
- Portlet 通信(三) Public render parameters(共享渲染/呈现参数)
- Android事件传递机制(四)
- netty学习(四)事件传递
- 利用指针传递参数
- 利用JS传递参数
- Activity之间传递参数(四)
- html事件传递参数
- (四)函数的参数传递——值传递
- ViewController之间通信,传递参数
- 利用javascript接收参数传递
- 利用call传递静态参数
- Leaflet入门之地图显示
- 例题6-8 二叉树的递归遍历 uva548
- 编辑联系5
- Lucene查询数据的相关度排序问题
- 十八岁的我们
- Portlet 通信(四) 利用事件传递参数
- Face Recognition(face_recognition) Using Hadoop Streaming API
- Nginx源码编译安装
- 最近收集的中科院研究生教学视频
- git添加远程库
- 如何让 vim 成为我们的神器
- CNN的全面解析
- poj2065 SETI(飘忽的英文题面)
- 验证码