Reputation: 233
I have two portlets in a liferay portal: an MVC portlet and a Vaadin portlet.
The first one sets a session attribute in this way:
long serviceId = 1;
PortletSession portSession = renderRequest.getPortletSession();
portSession.setAttribute("serviceId", serviceId, PortletSession.APPLICATION_SCOPE);
The second one reads it:
PortletRequest portletRequest = VaadinPortletService.getCurrentPortletRequest();
long serviceId = (long) portletRequest.getPortletSession().getAttribute("serviceId", PortletSession.APPLICATION_SCOPE)
The issue is that the session attribute read by the second portlet is null but not 1. What am I doing wrong?
Upvotes: 0
Views: 4807
Reputation: 663
Add
session.shared.attributes = Shared
in your liferay portal-ext.properties file. All Variables which starts with the keyword 'Shared' will be application scoped. If this is done, you no need to set
<private-session-attributes>false</private-session-attributes>
Upvotes: 1
Reputation: 2193
Please add <private-session-attributes>false</private-session-attributes>
in liferay-portlet.xml
for both portlets.
The detail of this tag is this as per DTD:
Element : private-session-attributes Set the private-session-attributes value to true if the portlet does not share session attributes with the portal. The default value is true. The property "session.shared.attributes" in portal.properties
specifies which session attributes are shared even when the
private-session-attributes value is true.Data Type : #PCDATA
Upvotes: 1