"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Tags/set.html" (14 Sep 2022, 64171 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:

Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)



Sets the value of a variable accessible with the GSP page.


<g:set var="tomorrow" value="${new Date() + 1}" />

<g:set var="counter" value="${1}" />
<g:each in="${list}">
    ${counter}.&nbsp; ${it} -> ${counter % 2 == 0 ? 'even' : 'odd'}
    <g:set var="counter" value="${counter + 1}" /><br/>

Using scopes:

<g:set var="foo" value="${new Date()}" scope="page" />
<g:set var="bar" value="${new Date() - 7}" scope="session" />

Using the body contents:

<g:set var="foo">Hello!</g:set>

Get a bean from the applicationContext by name:

<g:set var="bookService" bean="bookService"/>

Get a bean from the applicationContext by type:

<%@ page import="org.springframework.context.MessageSource" %>
<g:set var="messageSource" bean="${MessageSource}"/>



  • var - The name of the variable

  • value - The initial value

  • bean - The name or the type of a bean in the applicationContext; the type can be an interface or superclass

  • scope - Scope to set variable in, one of request, page, flash or session. Defaults to page.