Search code examples
liferayliferay-6liferay-theme

How to free a session variable in Liferay?


In Liferay, I'm using session variables for InterPortlet Communication.

PortletSession psession = request.getPortletSession();
String userId = (String) psession.getAttribute("userId", PortletSession.APPLICATION_SCOPE);

After use of this variable, I want to destroy it.

How to destroy, scrap the session variables in liferay?


Solution

  • Use removeAttribute method of PortletSession. It will remove attribute from session.

    In your case psession.removeAttribute("userId");

    This is applicable to request and session attributes also.