Jsf 2 使用JSF Liferay Portlet的PortletSession
我正在开发一个JSF2portlet,但我需要get全局会话变量 该请求适用于以下情况:Jsf 2 使用JSF Liferay Portlet的PortletSession,jsf-2,liferay,portlet,Jsf 2,Liferay,Portlet,我正在开发一个JSF2portlet,但我需要get全局会话变量 该请求适用于以下情况: FacesContext facesContext = FacesContext.getCurrentInstance(); PortletRequest request = (PortletRequest) facesContext.getExternalContext().getRequest(); 但会话为空: PortletSession session = request.getPort
FacesContext facesContext = FacesContext.getCurrentInstance();
PortletRequest request = (PortletRequest) facesContext.getExternalContext().getRequest();
但会话为空:
PortletSession session = request.getPortletSession(false);
如果将此代码放在liferay-portlet.xml文件中,效果会很好,但我无法进行IPC:Inter-portlet通信
<!-- Portlet session -->
<private-request-attributes>false</private-request-attributes>
<private-session-attributes>false</private-session-attributes>
但是如果为空,则有两个选项:
1) 在PortletSession中设置属性时,请使用此方法public void setAttribute(字符串名称、对象值、int scope),其中作用域应为PortletSession.APPLICATION\u scope
执行此操作时,请将其更改为liferayportlet.xml
<private-request-attributes>false</private-request-attributes>
<private-session-attributes>false</private-session-attributes>
false
假的
警告:已知对Liferay面使用false
。使用风险自负!
2) 使用HttpSession
而不是PortletSession
,要获取HttpSession
,请使用PortalUtil.getHttpServletRequest(portletRequest)
,并从httpServletRequest获取HttpSession
希望这有帮助
谢谢有两种选择:
1) 在PortletSession中设置属性时,请使用此方法public void setAttribute(字符串名称、对象值、int scope),其中作用域应为PortletSession.APPLICATION\u scope
执行此操作时,请将其更改为liferayportlet.xml
<private-request-attributes>false</private-request-attributes>
<private-session-attributes>false</private-session-attributes>
false
假的
警告:已知对Liferay面使用false
。使用风险自负!
2) 使用HttpSession
而不是PortletSession
,要获取HttpSession
,请使用PortalUtil.getHttpServletRequest(portletRequest)
,并从httpServletRequest获取HttpSession
希望这有帮助
谢谢警告:已知对Liferay人脸使用false
。使用风险自负!
我解决了配置liferay-portlet.xml的问题
1.)我仅使用以下命令更改了liferay-portlet.xml:
<private-session-attributes>false</private-session-attributes>
如果您获得会话属性
session.getAttribute("XXXXXX",PortletSession.APPLICATION_SCOPE);
session.setAttribute("NAME","VALUE",PortletSession.APPLICATION_SCOPE);
如果设置会话属性
session.getAttribute("XXXXXX",PortletSession.APPLICATION_SCOPE);
session.setAttribute("NAME","VALUE",PortletSession.APPLICATION_SCOPE);
警告:已知对Liferay面使用false
。使用风险自负!
我解决了配置liferay-portlet.xml的问题
1.)我仅使用以下命令更改了liferay-portlet.xml:
<private-session-attributes>false</private-session-attributes>
如果您获得会话属性
session.getAttribute("XXXXXX",PortletSession.APPLICATION_SCOPE);
session.setAttribute("NAME","VALUE",PortletSession.APPLICATION_SCOPE);
如果设置会话属性
session.getAttribute("XXXXXX",PortletSession.APPLICATION_SCOPE);
session.setAttribute("NAME","VALUE",PortletSession.APPLICATION_SCOPE);
克里斯蒂的第二个选择对我有用。当我设定
<private-session-attributes>false</private-session-attributes>
false
它导致我的portlet部署失败。分析xml文件时出错
我不知道为什么。Liferay 6.1.1版克里斯蒂的第二个选项对我很有用。当我设定
<private-session-attributes>false</private-session-attributes>
false
它导致我的portlet部署失败。分析xml文件时出错
我不知道为什么。Liferay版本6.1.1警告:已知对Liferay面使用false
。使用风险自负!
重新排序它会工作
<portlet>
<portlet-name>distribution</portlet-name>
<icon>/icon.png</icon>
<instanceable>false</instanceable>
<private-session-attributes>false</private-session-attributes>
...
...
...
...
分布
/icon.png
假的
假的
...
...
...
...
警告:已知对Liferay面使用false
。使用风险自负!
重新排序它会工作
<portlet>
<portlet-name>distribution</portlet-name>
<icon>/icon.png</icon>
<instanceable>false</instanceable>
<private-session-attributes>false</private-session-attributes>
...
...
...
...
分布
/icon.png
假的
假的
...
...
...
...
我不做portlet,但您不应该将true
作为create参数传递吗<代码>getPortletSession(true)。这在逻辑上更有意义。您在哪里设置了属性?请提供该片段。如果可能,您应该避免使用会话和会话共享。我在这里列举了许多更好的共享会话数据的解决方案:。更重要的是,请避免在JSF应用程序中使用它。我不使用Portlet,但您不应该将true
作为create参数传递吗<代码>getPortletSession(true)。这在逻辑上更有意义。您在哪里设置了属性?请提供该片段。如果可能,您应该避免使用会话和会话共享。我在这里列举了许多更好的共享会话数据的解决方案:。更重要的是,请避免在JSF应用程序中使用它。当我想要获取会话属性时,该属性为null,使用HttpSession而不是PortletSessionGet,仅当您在http会话中设置时,才从HttpSession获取该属性。您尝试过选项1吗?#2不太可能在Liferay 7.0+中工作;相反,在这里尝试一种解决方案:当我想要获取会话属性时,这是null,使用HttpSession而不是PortletSessionGet,仅当您在http会话中设置时,才从HttpSession获取该属性。您尝试过选项1吗?#2不太可能在Liferay 7.0+中工作;请尝试以下解决方案: