liferay组件间通信

主要用到标签:

<liferay-portlet:actionURL>、

<liferay-portlet:actionURL var="viewUrl"  portletName="viewtest_WAR_testportlet" name="firstlevel" >
    <liferay-portlet:param name="mvcPath" value="/html/viewtest/view.jsp"/>
    <liferay-portlet:param name="inputVal" value="12121212"/>
 </liferay-portlet:actionURL>


执行顺序: 前端发起请求-》目标组件firstLevel方法() -》目标组件 doView 方法

其中 portletName 为目标组件的namespace   name属性为调用目标组件portlet的方法 ;  以下为目标组件的portlet 代码


 <liferay-portlet:renderURL var="viewUrl1" portletName="viewtest_WAR_testportlet"  >
 <liferay-portlet:param name="inputVal1" value="3333333"/>
 </liferay-portlet:renderURL>
 执行顺序: 前端发起请求-》目标组件 doView 方法


目标组件portlet代码

@Override
	public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
			throws IOException, PortletException {
		String inputVal =ParamUtil.getString(renderRequest, "inputVal");
		String inputVal1 =ParamUtil.getString(renderRequest, "inputVal1");
		System.out.println("inputVal:"+inputVal);
		System.out.println("inputVal1:"+inputVal1);
		System.out.println("==============");
		System.out.println(renderRequest.getAttribute("inputVal"));
		renderRequest.setAttribute("inputVal", inputVal);
		super.doView(renderRequest, renderResponse);
	}
	
	public void firstlevel(ActionRequest request,ActionResponse response) throws Exception {   

		String inputVal =ParamUtil.getString(request, "inputVal");
		String inputVal1 =ParamUtil.getString(request, "inputVal1");
		System.out.println("-----inputVal:"+inputVal);
		System.out.println("-----inputVal1:"+inputVal1);
		request.setAttribute("inputVal", inputVal);
		request.setAttribute("inputVal1", inputVal1);
		sendRedirect(request, response);

	}
  

发起组件的view.jsp


<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ page import="com.liferay.portal.util.PortalUtil" %>
<portlet:defineObjects />
<liferay-portlet:actionURL var="viewUrl"  portletName="viewtest_WAR_testportlet" name="firstlevel" >
    <liferay-portlet:param name="mvcPath" value="/html/viewtest/view.jsp"/>
    <liferay-portlet:param name="inputVal" value="12121212"/>
 </liferay-portlet:actionURL>
 
 <liferay-portlet:renderURL var="viewUrl1" portletName="viewtest_WAR_testportlet"  >
 <liferay-portlet:param name="inputVal1" value="3333333"/>
 </liferay-portlet:renderURL>
 

<input id="inputVal1" name="inputVal1"/><br/>

 <input type="button" name="button" value="Action广播" οnclick="broadcast()" />  
 
  <input type="button" name="button" value="Renderer广播" οnclick="broadcast1()" />  
<script type="text/javascript">
	function broadcast(){
		var url ='<%=viewUrl.toString() %>';
		url += '&_viewtest_WAR_testportlet_inputVal1='+document.getElementById('inputVal1').value;
		window.location.href=url
	}
	
	function broadcast1(){
		var url ='<%=viewUrl1.toString() %>';
		url += '&_viewtest_WAR_testportlet_inputVal='+document.getElementById('inputVal1').value;
		window.location.href=url
	}
</script>





评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值