Legacy Knowledge Base
Published Sep. 10, 2025

Session Variables / User Scoped Variables Development

Written By

Liferay Support

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.
This article documents how to use Session Variables / User Scoped Variables in conjunction with portlets. There is also an included example in the details to help demonstrate how this has already been implemented.

Resolution

PortletSession values should be scoped on a portlet and user basis.

For example, you can see how the Web Form portlet stores data by looking at the saveDatabase method in WebFormPortlet.java. Follow that to a ServiceImpl file (ExpandoValueLocalServiceImpl.java, in this case) and you will see how persistence classes are used to store values in the database.

final PortletSession psession = request.getPortletSession();
psession.setAttribute(key, value, PortletSession.APPLICATION_SCOPE);

// READ
psession.getAttribute(key, PortletSession.APPLICATION_SCOPE);

Use a prefix LIFERAY_SHARED_ for your key, so your variable will be available for all the portlets (those which share their session with the other and those which not).

If you need to get the resource from the portal, use HttpSession and not PortletSession anymore.

Did this article resolve your issue ?

Legacy Knowledge Base