Grails – GSP

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

  1. Variables placed in request scope last just long enough to be displayed in the response and then are discarded.
  2. Values in flash scope (commonly used for error messages in Grails) can survive a single redirect.
  3. Session scope is used for values that should stick around for multiple requests, but are limited to the current user.
  4. Values placed in application scope are “global”—they last for as long as Grails is running, and they are shared across all users.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s