Foros de discusión

Liferay 7 Share Sessions between Portlets (Bundles)

Mario Starlinger, modificado hace 7 años.

Liferay 7 Share Sessions between Portlets (Bundles)

New Member Mensajes: 20 Fecha de incorporación: 20/04/15 Mensajes recientes
Hello everybody!

I am working on Liferay 7 and I try to share sessions among the whole portal. I set HTTP-Session in doView-Method of Portlet 1:

PortletSession portletSession = renderRequest.getPortletSession(); 
portletSession.setAttribute("test-session", "test", PortletSession.APPLICATION_SCOPE);


On Portlet 2 I try to access the session attribute set on portlet 1:
PortletSession portletSession = renderRequest.getPortletSession(); 
System.out.println("Session: " + portletSession.getAttribute("test-session", PortletSession.APPLICATION_SCOPE));


But I get null.

I also set this two parameters in Portet-Component annotation of each portlet:
"com.liferay.portlet.private-session-attributes=false",
"com.liferay.portlet.requires-namespaced-parameters=false"


When I print the Session-Id I fount out that it is equal in the two portlets.

I also tried HTTP-Session but the result is the same:
HttpSession httpSession = PortalUtil.getHttpServletRequest(renderRequest).getSession();


Does anybody know how to share Session between Portlets or Portal-Wide?

Thanks in advance,

Mario Starlinger
thumbnail
Olaf Kock, modificado hace 7 años.

RE: Liferay 7 Share Sessions between Portlets (Bundles)

Liferay Legend Mensajes: 6403 Fecha de incorporación: 23/09/08 Mensajes recientes
As I try to stay away from session as much as possible, I've not yet tried session handling in the current version. However, as an ugly workaround - please see my additional answer to this question on stackoverflow that explains why PortalUtil.getHttpServletRequest() does not result in the servletRequest that the application server has been handling - thus this is not what you need for real-global-http-session sharing.

I'm sure there's an easier and better way - just not enough time to dig into an area that I try to avoid at all cost... Sorry. Maybe this answer bumps your question up the "Recently changed" list that someone else finds it for a less hacky answer.
thumbnail
Manish Kumar Jaiswal, modificado hace 7 años.

RE: Liferay 7 Share Sessions between Portlets (Bundles)

Regular Member Mensajes: 153 Fecha de incorporación: 25/11/08 Mensajes recientes
Hi Mario ,

did you find the solution ..i am facing the same issue ..

thanks
Manish
thumbnail
Ketan Savaliya, modificado hace 7 años.

RE: Liferay 7 Share Sessions between Portlets (Bundles)

Regular Member Mensajes: 117 Fecha de incorporación: 3/03/11 Mensajes recientes
Manish Kumar Jaiswal:
Hi Mario ,

did you find the solution ..i am facing the same issue ..

thanks
Manish


Use below properties to shared the session between portles.
#
# Portlets that have been configured to use private session attributes in
# liferay-portlet.xml may still want to share some session attributes. This
# property allows you to configure which session attributes will be shared.
# Set a comma delimited list of attribute names that will be shared when the
# attribute name starts with one of the specified attribute names. For
# example, if you set the value to "hello_,world_", then all attribute names
# that start with "hello_" or "world_" will be shared.
session.shared.attributes=COMPANY_,


HTH!!
Lubna Shumaila, modificado hace 6 años.

RE: Liferay 7 Share Sessions between Portlets (Bundles)

New Member Mensajes: 2 Fecha de incorporación: 22/09/16 Mensajes recientes
To access the session variables in the portal , it is not necessary to give any entry in portal-ext file.

It can be done by using LIFERAY_SHARED_" default keyword provided by liferay.

PortletSession portletSession = renderRequest.getPortletSession();
portletSession.setAttribute("LIFERAY_SHARED_test-session", "test", PortletSession.APPLICATION_SCOPE);

In the second portlet access it by using same

portletSession.getAttribute("LIFERAY_SHARED_test-session", PortletSession.APPLICATION_SCOPE));

Also do not forget to add extends GenericPortlet in the main class of your portlet at both sender portlet and receiving portlet.

public class TestController extends GenericPortlet {}
Lubna Shumaila, modificado hace 6 años.

RE: Liferay 7 Share Sessions between Portlets (Bundles)

New Member Mensajes: 2 Fecha de incorporación: 22/09/16 Mensajes recientes
The shared session variables can also be accessed at the theme and velocity web content

$request.getSession().getAttribute("LIFERAY_SHARED_test"))