主要用到标签:
<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>