Can I get down now dad?

Tramps like us, baby we were born to code

Digging the crazy Grails thing

So here goes, my first Grails app. A simple todo list

First create me an application with: grails create-app todo

Then create a domain class with: grails create-domain-class and tell to create a class called todo.

Edit the domain class, add some fields and constraints as follows:

class Todo {

String description
String type
Date dueDate

static constraints = {
description(unique:true,,blank:false,length:5..30)
type(nullable:false,blank:false,inList:[’work’,'private’])
}
}

Then generate a controller with: grails create-controller and tell it to use Todo.

Finally edit the controller class TodoController.groovy an tell it to dynamically generate the scaffoled code based on the Todo domain class.

class TodoController {

def scaffold = Todo
}

And with just that tiny bit code I have a running app. I can test it locally and when I am happy create a war file with grails war.

Finally, and wondefully I can just upload this to my tomcat server and it works. See the demo app here.

There is a very real chance I may wet my pants.

Final note, the database is just a in memory db so things will disappear.

Leave a Reply