简体   繁体   English

在Liferay Portlet中设置的Velocity Template中检索会话属性

[英]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. 在我的Portlet中,我在会话中设置了一些属性,我希望在Liferay使用的速度模板中使用它。

I set the attributes on PortletSession as follows: 我在PortletSession上设置属性如下:

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: 现在我希望在Liferay的home.vm模板中使用这些,但无论我尝试什么,都没有用:

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

I even put the key in the portal.properties: 我甚至把密钥放在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. 显然我需要将private-session-attributes为false。 I tried that before, but the DTD is very specific where it needs the tag. 之前我尝试过,但DTD在需要标签的地方非常具体。

After placing it at the right place, it worked. 将它放在正确的位置后,它工作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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