Liferay通信-PortletURL

编写Portlet组件A(mvc)

  1. 编写后端java业务处理

    public class PortletUrlAPortlet extends MVCPortlet {
    	private Logger log = LoggerFactory.getLogger(PortletUrlAPortlet.class) ;
    	@Override
    	public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
    			throws IOException, PortletException {
    		long uid = PortalUtil.getUserId(renderRequest) ;
    		log.info("PortletUrlAPortlet doView exec --- {}", uid);
    		super.doView(renderRequest, renderResponse);
    	}
    }
    
  2. 编写前端jsp页面

    <%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
    <%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %><%@
    taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %><%@
    taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %><%@
    taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
    <liferay-theme:defineObjects />
    <portlet:defineObjects />
    <p>
    	<%-- 1.  引入liferay-theme的标签后页面自动存在变量plid --%>
    	<%-- 2. portletName目标Portlet的名称,可以F12打开浏览器查看页面,
    	         元素<span id="p_mvc_ipc_PortalUrlBPortlet"></span>看到,
    	         去掉p_前缀即可 
    	--%>
    	<%-- 3. input的名称不能直接使用 <portlet:namespace/>作为username的前缀,
    	        因为每个portallet的namespace不一样,
    			需要使用组件B的namespace值,可打印到页面上显示出来,然后粘贴到这里
    	--%>
    	<liferay-portlet:renderURL var="updateUrl" plid="<%=plid %>" portletName="mvc_ipc_PortalUrlBPortlet">
    	 	<liferay-portlet:param name="password" value="123"/>
    	</liferay-portlet:renderURL>
    	<form method ="post" action ="${updateUrl}">
    		用户名:<input type ="text" name ="_mvc_ipc_PortalUrlBPortlet_username" value ="yicj"/>
    		<input type ="submit" value ="提交" />
    	</form>
    </p>
    

编写Portlet组件B (mvc)

  1. 编写后端java业务处理

    public class PortletUrlBPortlet extends MVCPortlet {
    	private Logger log = LoggerFactory.getLogger(PortletUrlAPortlet.class) ;
    	@Override
    	public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
    			throws IOException, PortletException {
    		long uid = PortalUtil.getUserId(renderRequest) ;
    		// 1. 组件A提交过来的用户名
    		String username = ParamUtil.getString(renderRequest, "username") ;
    		String password = ParamUtil.getString(renderRequest, "password") ;
    		log.info("PortletUrlBPortlet doView exec ---uid: {} , username: {}, password: {}", uid, username, password);
    		// 2. 将数据放入request以备前端显示
    		renderRequest.setAttribute("username", username);
    		renderRequest.setAttribute("password", password);
    		super.doView(renderRequest, renderResponse);
    	}
    }
    
  2. 编写前端jsp代码片段

    <p>
    	<b><liferay-ui:message key="portalUrlB.caption"/></b><br/>
    	username : ${username } <br/>
    	password : ${password }<br/>
    </p>
    
上一篇:el-upload http-request上传覆盖默认,显示上传成功的 icon 和 默认的进度条 以及上传失败自动删除


下一篇:golang操作sqlite3