留言板

Portlet session and Thread Safety

Francesco Scali,修改在11 年前。

Portlet session and Thread Safety

New Member 帖子: 14 加入日期: 09-11-2 最近的帖子
Hi,
In Liferay 5.2.3 I'm using LIFERAY_SHARED_ prefix to share session attributes between the portal and the portlets.
Sometimes, but not always,from my IceFaces portlet I cannot retrieve the attribute previously set in session during my custom action (configured in servlet.service.events.pre) Do I have to access the session in synchronized mode? How is it possible (since in Icefaces session I cannot access the httpsession)?
The code I use to retrieve the attribute from the IceFaces portlet is:

FacesContext facesContext = FacesContext.getCurrentInstance();
PortletSession portletSession =
(PortletSession)facesContext.getExternalContext().getSession(false);
Object theSessionObj = portletSession.getAttribute(key, scope);

Thanks

Francesco
thumbnail
Neil Griffin,修改在11 年前。

RE: Portlet session and Thread Safety

Liferay Legend 帖子: 2655 加入日期: 05-7-27 最近的帖子
If you're using ICEfaces2 or ICEfaces3, then you can get the underlying HttpSession like this:
import com.liferay.portal.util.PortalUtil;
...
FacesContext facesContext = FacesContext.getCurrentInstance();
PortletRequest portletRequest = (PortletRequest) facesContext.getExternalContext().getRequest();
HttpSession httpSession = PortalUtil.getHttpServletRequest(portletRequest).getSession();
Francesco Scali,修改在11 年前。

RE: Portlet session and Thread Safety

New Member 帖子: 14 加入日期: 09-11-2 最近的帖子
unfortunately we've got IceFaces 1.8.2 emoticon
Any way to do this ?
thumbnail
Neil Griffin,修改在11 年前。

RE: Portlet session and Thread Safety

Liferay Legend 帖子: 2655 加入日期: 05-7-27 最近的帖子
For ICEfaces 1.x I would recommend that you consider adding PortletFaces-Tools as a dependency to your portlet. It has some nice convenience features that provide improved ICEfaces 1.x integration with Liferay.

The problem is that ICEfaces 1.x only has access to Liferay-related objects during the initial RENDER_PHASE of the portlet lifecycle. After the initial render, ICEfaces 1.x does all the ajax calls with a servlet which does not have access to the original PortletRequest.

In particular, the Liferay.java class in PortletFaces-Tools shows how to cache important objects from PortletRequest during the initial render.

ICEfaces 2.x and 3.x does not have this problem, because Liferay Faces Bridge will use the RESOURCE_PHASE of the portlet lifecycle for Ajax, which always has access to Liferay-related objects.
thumbnail
Neil Griffin,修改在11 年前。

moved thread to Liferay Faces forum

Liferay Legend 帖子: 2655 加入日期: 05-7-27 最近的帖子
moved thread to Liferay Faces forum