简体   繁体   中英

Retrieving Session attributes in Velocity Template set in Liferay Portlets

In my Portlet I set some attributes in the session which I wish to use in the velocity template that Liferay uses.

I set the attributes on PortletSession as follows:

portletSession.setAttribute("key", "value", PortletSession.APPLICATION_SCOPE);

Now I wish to use these in my home.vm template of Liferay, but whatever I tried, nothing works:

$request.get("key") 
$request.getAttribute("key") 
$request.getSession().getAttribute("key")
$session.getAttribute("key")

I even put the key in the portal.properties:

session.shared.attributes=key

But that does not seem to work either. Can anyone point me in the right direction?

Found the answer myself.

Apparantly I needed to set the private-session-attributes to false. I tried that before, but the DTD is very specific where it needs the tag.

After placing it at the right place, it worked.

将“LIFERAY_SHARED_”前缀添加到会话属性名称应该足够了,因为session.shared.attributes属性的值默认包含它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM