Search code examples
grailsgsp

How to use grails <g:set> tag session scope?


I am trying to use the g:set tag on my gsp. As long as I am in one page and the scope is default or page, it works fine. When I am trying to change the scope to session its not working.

My understanding is I should be able to access that variable not only on that page but also on others when the scope is session, however, I might be wrong.

In a brand new 2.0.3 application I have this script on my index.gsp body and it works as expected.

<g:set var="bar" value="${new Date() - 7}" scope="page" />
<div class="message" role="status">${bar}</div>

However if I change the scope to session it doesn't work,

    <g:set var="bar" value="${new Date() - 7}" scope="session" />
    <div class="message" role="status">${bar}</div>

neither on any other page.


Solution

  • Have you tried:

    <div class="message" role="status">${session.bar}</div>
    

    http://grails.org/doc/latest/guide/theWebLayer.html#variablesAndScopes