Liferay 7 not able to set the global session attribute

天大地大妈咪最大 提交于 2019-12-04 17:46:17

This is not a bug! Liferay is a portlet container and in the portlet specification every portlet is a different context with a different session. You are trying to save data in a portlet session and recover it in other portlet session, its not correct. Liferay provides a method to get the portal global session:

        PortalSessionThreadLocal.getHttpSession();

This session can be retrieved from every portlet of the portal, BUT is important specify that save data in the global session is strongly discouraged in clustered environments mainly because if you save a instance from a class that only exists in a portlet you can get ClassNotFoundException from other portlet that doesn't know that class. Global session is only recommended for save primitive data.

We had the same issue we are using LR7.0. I am not sure if that is bug or something. But as a workaround this what we did. We are getting the original session.

HttpServletRequest httpRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)); HttpSession session = httpRequest.getSession(); session.setAttribute("testAttr","hi");

Hope that helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!