Sunday, August 10, 2008

Enabling the AJAX Spinner in Grails

For standard page requests, browsers use an animated icon as an indicator to the user that the browser is waiting for the request to complete. However, for AJAX calls that are initiated via JavaScript in a separate thread the browser icon does not animate. So, typically the application developers use an animated icon within the page to notify the user the page is waiting for a request to complete. In an effort to simplify web development Grails automatically includes an animated spinner icon when using the Prototype or AJAX frameworks.

To enable the Grails AJAX spinner you must include the Prototype or JavaScript typically using the or tags. But these declarations can not be included just any place within your page. These declarations must come before the tag since it includes the application.js file that registers the spinner with Prototype and requires Prototype variables to be available.

If you are using the default layout found in main.gsp, you can declare the Prototype or inclusions in one of two places. You can either make the declarations in the header section of an individual view such as in this example:

<title>Make and Model</title>
<meta equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="layout" content="main">
<g:javascript library="scriptaculous"/>
Or in the header section of the main.gsp prior to the application declaration such as in this example.

<title><g:layoutTitle default="Grails" /></title>
<link rel="stylesheet" href="${createLinkTo(dir:'css',file:'main.css')}" />
<link rel="shortcut icon" href="${createLinkTo(dir:'images',file:'favicon.ico')}" type="image/x-icon" />
<g:layoutHead />
<g:javascript library="scriptaculous" />
<g:javascript library="application" />
If you are not using the standard layout just make sure you put the Prototype or tag prior to the application tag and include the following or similar div tag found in the default layout.

<div id="spinner" class="spinner" style="display:none;">
<img src="${createLinkTo(dir:'images',file:'spinner.gif')}" alt="Spinner" />

Friday, August 8, 2008

Groovy Programming Review

I recently finished reading Groovy Programming: Dynamic Productivity for the Java Developer by Venkat Subramaniam. I found it to be a very good and inspiring book. For experienced Groovy developers, the first half has some jems so it is worth reading but the second half is what makes the book. Venkat's explination of Groovy's Meta Programming and dynamic features makes a difficult topic very easy to understand with good simple examples. His explination of building builders inspired me to evaluate some of the behaivor tests I was writing at the time. It helped me to realize the hierartical data structure I was building in code for test data could be better represented using a custom builder which ultimately made the code much easier to read and maintain.

I recommend every serious Groovy and Java developer read at least the second half of the book so congradulations Venkat on an excellent book.

The Ultimate Enterprise Java Build Solution Revisited

In May of 2009, I wrote the blog post The Ultimate Enterprise Java Build Solution . Over the past 7 years since I wrote the post I have help...