GSP
Grails uses GSP for the presentation tier. The Groovy in Groovy Server Pages not only identifies the underlying technology, but also the language you can use if you want to write a quick scriptlet or two. Groovy Taglib and partial templates give you a more sophisticated way of sharing code and behavior across Web pages.
GSPs are the foundation of Grails’ page-centric MVC world view. The page is the basic unit of measure. The List page offers links to the Show page. The Show page allows you to click through to the Edit page, and so on. Whether you’re a seasoned Struts developer or a recent Rails enthusiast, you’re already familiar with this type of Web life cycle.
A sample GSP page (list.gsp) depicted below:
<g:each in=”${userInstanceList}” Satus=”i” var=”userInstance”> <tr class=”${(i%2)==0?’odd’ : ‘event’}”> <td> <g:link action=”show” id=”${userInstance.id}”> ${fieldValue{bean:userInstance, field:’id’)} </g:link> </td> <td>${fieldValue(bean:userInstance, field:’login’)}</td> <td>${fieldValue(bean:userInstance, field:’password’)}</td> <td>${fieldValue(bean:userInstance, field:’role’)}</td>
Scopes in Grails
There are four scopes in Grails: request, flash, session, and application. Each one has a different lifespan
- Variables placed in request scope last just long enough to be displayed in the response and then are discarded.
- Values in flash scope (commonly used for error messages in Grails) can survive a single redirect.
- Session scope is used for values that should stick around for multiple requests, but are limited to the current user.
- Values placed in application scope are “global”—they last for as long as Grails is running, and they are shared across all users.