RE: Outject session scoped attributes from portlet to portal

Ghenadii Batalski, modified 6 Years ago. New Member Posts: 7 Join Date: 7/31/17 Recent Posts

Hello Community,

we've got a very simple requierement to show some information about the logged in user in a header of a portal. For that simple feature i would "outject" some attribute into the global session scope of the logged in user and grasp it somewhere in an .ftl template e.g.:

HttpSession session = request.getSession();
session.setAttribute("MYATTR", attrvalue);

just in the near of the 

session.setAttribute(CASWebKeys.CAS_LOGIN, login);

 

But this intuitive approach just won't work for MYATTR (despite it nicely works for CAS_LOGIN). I already tried to prefix the attribute with LIFERAY_SHARED_ but without effect. It worth mentioning that the  documentation of 

session.shared.attributes

already warns about the impossibility:

Note that this property is used to specify the sharing of session attributes from the portal to the portlet. This is not used to specify session sharing between portlet WARs or from the portlet to the portal.

 

but what is the correct solution for such a simple requirement?

 

Thank you and regards, Gena

thumbnail
Amos Fong, modified 6 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts

If you're in a portlet, try setting private-session-attributes to false.

 

However you may want to read Dave's blog on this issue and find a different method to achieve what you want:

https://community.liferay.com/blogs/-/blogs/resident-evil-death-to-sessions