Session Liferay设置portlet会话值

Session Liferay设置portlet会话值,session,liferay,portlet,Session,Liferay,Portlet,我有两个portlet,一个是MVCPortlet,另一个是JSFPortlet。 我想将属性从MVCPortlet发送到另一个 在MVCPortlet中: @Override public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { PortletSes

我有两个portlet,一个是MVCPortlet,另一个是JSFPortlet。 我想将属性从MVCPortlet发送到另一个

在MVCPortlet中:

@Override public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { PortletSession portletSession = actionRequest.getPortletSession(); portletSession.setAttribute("example", "SET ATTR PROCESS ACTION", PortletSession.APPLICATION_SCOPE); .... FacesContext facesContext = FacesContext.getCurrentInstance(); PortletRequest request = (PortletRequest)facesContext.getExternalContext().getRequest(); PortletSession session = request.getPortletSession(false); String testString = (String) session.getAttribute("example",PortletSession.APPLICATION_SCOPE); @凌驾 public void processAction(ActionRequest ActionRequest, ActionResponse(ActionResponse)引发IOException、PortletException{ PortletSession PortletSession=actionRequest.getPortletSession(); setAttribute(“示例”,“设置属性进程操作”, PortletSession.应用程序(适用范围); .... 在其他JSF Portlet中:

@Override public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException { PortletSession portletSession = actionRequest.getPortletSession(); portletSession.setAttribute("example", "SET ATTR PROCESS ACTION", PortletSession.APPLICATION_SCOPE); .... FacesContext facesContext = FacesContext.getCurrentInstance(); PortletRequest request = (PortletRequest)facesContext.getExternalContext().getRequest(); PortletSession session = request.getPortletSession(false); String testString = (String) session.getAttribute("example",PortletSession.APPLICATION_SCOPE); FacesContext FacesContext=FacesContext.getCurrentInstance(); PortletRequest请求=(PortletRequest)facesContext.getExternalContext().getRequest(); PortletSession=request.getPortletSession(false); String testString=(String)session.getAttribute(“示例”,PortletSession.APPLICATION_SCOPE); 但是testString的值总是返回null

两个portlet都在liferay-portlet.xml中有配置:

<private-session-attributes>false</private-session-attributes>  
false
我是liferay的新手。谢谢您的帮助!

尝试在属性名称前添加“liferay\u SHARED\u”,即:

portletSession.setAttribute("LIFERAY_SHARED_example", "SET ATTR PROCESS ACTION", PortletSession.APPLICATION_SCOPE);
然后用同样的名字读:

String testString = (String) session.getAttribute("LIFERAY_SHARED_example", PortletSession.APPLICATION_SCOPE);
此外,您还可以通过在portal-ext.properties中指定前缀来更改此前缀:

session.shared.attributes=CUSTOM_PREFIX_

您必须在每个portlet的liferayportlet.xml文件中将属性“private session attributes”设置为false。在
标记中添加以下行:

<private-session-attributes>false</private-session-attributes>
false

谢谢,但当我在JSF portlet中打印会话属性时,它仍然返回空值:
枚举en=session.getAttributeNames();

while(en.hasMoreElements()){``System.out.println(en.nextElement());`}`结果:
javax.portlet.faces.viewIdHistory.view
我已经把它放在了liferay-portlet.xml中。你可以在上面看到它
false
已经知道它会导致JSF portlet中的内存泄漏。请使用这个博客中的另一个解决方案: