Portlet之间传值


2种liferay portlet 之间传至方法。

NO.1

portlet.xml

<supported-public-render-parameter>message1</supported-public-render-parameter>

<public-render-parameter>
		<identifier>message1</identifier>
		<qname xmlns:x="http://www.liferay.com/public-render-parameters">x:message1</qname>
	</public-render-parameter>


对参数进行赋值的话,就是在Action中用下面这句话:
actionResponse.setRenderParameter("参数名", 参数值);
获取的话,就直接像取其它参数一下直接获取:
在Action中,String 变量 = ParamUtil.getString(request, "参数名", "默认值");
在JSP中,<%=renderRequest.getParameter("参数名")%>


NO.2

liferay-portlet.xml
		<private-request-attributes>false</private-request-attributes>
		<private-session-attributes>false</private-session-attributes>


public String index() {

		HttpServletResponse resp = ServletActionContext.getResponse();
        org.apache.struts2.portlet.servlet.PortletServletResponse struts2Resp = (org.apache.struts2.portlet.servlet.PortletServletResponse) resp;     
        
        HttpServletRequest req = ServletActionContext.getRequest();
		org.apache.struts2.portlet.servlet.PortletHttpSession strutsSession = (org.apache.struts2.portlet.servlet.PortletHttpSession) (req
				.getSession());
		
		if(Validator.isNull(message)){
			 message = (String)strutsSession.getPortletSession().getAttribute("message",PortletSession.APPLICATION_SCOPE);
		}
		strutsSession.getPortletSession().setAttribute("message", message, PortletSession.APPLICATION_SCOPE);
		return SUCCESS;
	}


	String message = (String)renderRequest.getPortletSession().getAttribute("message",PortletSession.APPLICATION_SCOPE);		renderRequest.setAttribute("message", message);

你可能感兴趣的:(liferay)