Chariot Training Classes

Training Courses

I run Chariot's training and mentoring services. We provide training in AngularJS, HTML5, Spring, Hibernate, Maven, Scala, and more.

Chariot Education Services


Chariot Emerging Tech

Learn about upcoming technologies and trends from my colleagues at Chariot Solutions.


Chariot Conferences


Entries in grails (17)


Grails and Spring WebFlow

Everyone has had to code an application at some point where they were forced into a particular set of navigational flows. There are a few ui-centric workflow packages out there, including Open Symphony's OSWorkflow, and Spring's WebFlow. Other developers at my shop have worked with WebFlow and were pleased with its' features. But did you know that Grails embeds WebFlow and makes it available within its' controllers automatically?

WebFlow Basics

For a thorough introduction to Spring Webflow, I suggest visiting the SpringSource site. However, in general, webflows can be broken up into distinct components:

  • State - This is a 'definable moment' within the webflow, such as a View State, where the application is waiting on user input.

  • Transition - An event, often fired by a user taking an action, that moves the webflow from one state to another.
  • Action - Code that can be performed within a transition, or on the start or ending of a given State

  • View - A (GSP) page that is rendered during a 'view state'.
  • Flow Scope - A semi-session-like container that lives for the life of the webflow. Data captured from one view to the next

Without too much more ceremony, I can simply say that although Spring WebFlows are a great feature, and take a lot of pain out of implementing flow-based application logic, they are made even easier by Grails.

A Grails WebFlow

Here is a simple webflow that represents a fragment of a voting application. Call it KrimpleVote (or HangingChad, the system)... (I have since lost the image itself...) To build a webflow in Grails, simply create a closure ending in Flow, and embed the states, transitions and actions as inner closures. It's easier to read than it is to describe:

def registrationFlow = {

showDisclaimer {
on("continue").to "lookupVoter"

lookupVoter {
on("selfRegister").to "selfRegister"
on("find") {
if (!params.ssn) {
return error()

def voter = Voter.findBySsn(params.ssn)
if (voter == null || voter.ssn == null) {
return error()
} else {
flow.voter = voter
}.to "showRegistration"
on("return").to "lookupVoter"

selfRegister {
on("continue") {
Voter v = new Voter(params)
if (!v.validate()) return error()
flow.voter = v
}.to "chooseParty"

View states are closures that do not automatically transition to another state. Take a look at the showDisclaimer closure as it's a view state. It waits for the 'continue' event to be sent as a transition from the user. You do that by submitting a form to the same closure (registration) and embedding a submitButton within the form with the name of the transition:

fragment of showDisclaimer.gsp

Note: You have to put the GSPs in a subdirectory named registration under the controller's views as it puts all webflow views in a subdirectory by flow name (without Flow). Also, the pages are pretty straightforward as well. Another nice thing is that it automatically handles the flow continuation key for you.

I've been (slowly) getting around to putting that Voter application together as a sample. Once I do, I will post it for download. Until then, I'll post some snippets as I learn more.

For more Flow goodness, check out the grails documentation page on it.


Emerging Tech Conference Day 1 Recap

What an entertaining day! Lots of fun sessions to attend, and attendance hit the 400 person cap, a record for ETE. I attended talks on Flex, OSGi, Hadoop, Seam, and gave a talk on Grails. At the end of the day everyone went to the World Cafe for drinks, and the guitar player actually whipped out Paranoid Android from O.K. Computer--what a riot.

Of the talks, the one that blew my mind a bit was Hadoop. Although I'm not 100% sure I get it yet, it looks like those LISP / AI Comp Sci geeks ended up working at Google, and Yahoo... Time for me to dust off that old engineering hat and start learning a completely different way of programming. For those of you not in the know (believe me, it includes myself), Hadoop is a massively parallel architecture for running queries against data. Think "how does Google manage search indexing and processing" and you get the idea that no software built by standard humans could keep up. It turns out Google runs that web index in MEMORY across many nodes. Wow.

My interest in Grails is still ongoing, and I have to say that you can only talk about so much in one hour. I'm wondering what other presenters end up doing for a one hour intro (and someone from G2One is doing another Grails talk tomorrow at ETE). Mine was mostly setting the stage (Groovy and what it offers, Grails as a platform) then I dove into a 25 minute demo. I ended up covering domains, (a simple domain, scaffold the UI, one to many) and showed them how to switch databases. But I pretty much ran out of time to do anything else. Hopefully in the future I can prepare a more advanced dive.

I liked what I saw from Seam, and have it in my Mac downloads folder to screw around with. I'm not sure I want to use JSF on the front end, although the speaker explained that Seam manages JSF a bit for you and simplifies it. What I don't get yet is the fact that you're constantly re-deploying an exploded WAR or EAR, and I'm wondering how that works in practice. (Then again, Grails re-deploys too, but it's a simple WAR without any EJBs, etc..) More on Seam in a later post.

Finally, I got to see the hubub on OSGi from two speakers--our own Dmitry Sklyut and Michael Redlich from ExxonMobil. Dmitry's was on Spring OSGi, and how you can essentially create a module per ApplicationContext. In the end, it's about injection in Spring, so essentially you can either publish a bean or reference it using Spring DI. Pretty cool. Michael's talk was more general (here is how OSGi works) with some great sample code. He was using Equinox as the container in the demo. I did like the comment made by Dmitry toward the end--he felt that OSGi in general is at least 5 months too early for general use. But he also said (and I COMPLETELY AGREE) that he's been waiting too long for application software that can be treated like pluggable Legos. Maybe OSGi is the answer, but I'm thinking it will take Spring to sort that one out.

I ran the MP3 audio recording of three sets of sessions (lightweight, agile and ruby) so between pulling off audio and making sure things got recorded it was a lot of running around. Hats off to the Drexel student helpers as they remembered to stop/start the audio recording gear. By the way, I'm using the iKey Audio plus, a little hardware box that takes any of three input types (line in, mic in, phono in) and directly records it to an USB memory stick as either an MP3 (128 - 320 kbit) or a full-out wav file. Pretty nifty. As long as the quality holds up, we'll be publishing various sessions on my Chariot Tech Cast podcast.


Presentation and Notes from my Grails talk

Here is a PDF of my Grails talk at the Philly Emerging Tech conference today. It is a general overview of Groovy and Grails, and was meant to be delivered with a 20-30 minute demo. My demo consisted of creating a few domain classes and controllers, and showing scaffolding.

I ran out of time in 60 minutes, but if I had enough I would have shown Glen Smith's Gravl as a sample application (with full props to Glen, as that app is a tremendously useful example).

There were a few questions asked at the end... One of them was whether you can create a jndi datasource in Grails. Yes, you can. An attribute you can apply to a datasource (from the Grails docs):

dataSource {
jndiName = "java:comp/env/myDataSource"

The full URL is here.

Thanks to everyone who attended; it was a packed room and Grails seemed to generate a lot of interest. Right now I'm listening to a talk on Seam, which seems to be JBoss's annotation-driven answer to Rails and Grails. More later.


A few tips for Grails Database Setups...

Here are a few quick tips for setting up the Grails datasources in grails-app/conf/DataSource.groovy:

  • To log all Hibernate queries, use
    loggingSql = true 
    either in the initial dataSource closure, or in a specific connection pool (Development, Test, Production)
  • If you didn't have time to create a database and are just prototyping domain relationships, don't worry about this file yet! Just open up BootStrap.groovy in the same directory, and wire up your domain classes like this:

    class BootStrap {
    def init = { servletContext ->
    def p1 = new Employee(firstName: "Ken",

    This example above uses the embedded Hypersonic SQL in-memory database. Each time you spin up the application server, the default entry for the development instance creates the tables, and on the way out, drops them (create-drop). You could choose to switch to MySQL, for example, and use Create on one startup. Then, once you're done, switch to update. This will ensure that the data you've created stays in the database (and you can comment out the original BootStrapping code: don't delete it unless you want to type it in all over again once your database gets screwed up).

  • Keep in mind, anything you put at the initial dataSource closure gets inherited into the specific configurations. So, you might have the same database vendor in all three environments: use the same driver.
  • You can have different environments, and not just three. Change the environment names, and when you start up, pass the -Dgrails.env=production or -Denv=supersecretprobation flag to grails run-app and you'll use those configurations.


G2Exchange Recap, Day #3

The final day of the Groovy Grails Exchange had some great sessions as well. I attended Alexandreu Popescu's Groovy and SQL talk, which was a good introduction to all things SQL and database migration. He mentioned several tools I've never worked with, including dbmigrate, DdlUtils, and LiquiBase. Personally, I've always been a database scripts person, but I will definitely look into those tools.

The second session I attended was the Grails UI Extreme Makeover by Glen Smith. That man is hilarious, and also very informative. It was there that I scored my Kualoa (it was a cheap shot, I asked him when his charting plugin would be appearing online). He went into detail about Yahoo UI, which includes lots of nifty widgets like tagclouds, calendar controls, tool tips, in-place editors, and autocompletion.

In the afternoon, Jason Rudolph hosted a Refactotum, which was an introduction into how to work on an open source project without spending your whole life doing it. There was a great back and forth between Scott Davis, Jason, Dierk Koenig, and others on testing strategies. More information on Jason's blog here. Apparently the session led to over six new patches to the Grails framework. Now, if only I could figure out how to get my Ant build to actually call my new Unit Test, I may have a contribution as well!