Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
wolfgang kubens
Set session value from velocity template
July 7, 2010 3:48 PM
Answer

wolfgang kubens

Rank: New Member

Posts: 12

Join Date: July 15, 2009

Recent Posts

I have created a structure and a velocity template. As far as good. The idea is to render different outputs depending on a simple flag which will set after first view:

 1#set ($sessionService=$serviceLocator.findService("net.woocoom.service.SessionService.impl"))
 2#set ($flag=$sessionService.getAttribute('flag'))
 3
 4#if ($flag==false)
 5  #set ($flag = $sessionService.setAttribute('flag',true))
 6
 7  <p>viewed first time in this session</p>
 8
 9#else
10
11  <p>viewed before in this session</p>
12
13#end

I know that I have just access to restricted variables inside velocity templates. Therefore I assume that a service could be helpful, but I am not sure.

Does anybody know if this would be possible or does anybody know another similar approach?

Thanks in advance
Wolfgang