Prototyping With Grails
Prototyping With Grails
Mohd Suhaizal
Software Engineer
Jaringan Data Sdn Bhd
EFFORT?
TIME?
SKILLS?
Enter Groovy and Grails...
Groovy at a glance
●
A dynamic language for the JVM
●
Inspired by languages such as Smalltalk,
Python, Ruby and the likes...
●
Features dynamic typing, Meta Object
Protocol (MOP), DSL, seamless
integration with Java libraries ...
Grails: A little bit of history
Guillaume Laforge on the Groovy lists in 2005:
Ruby on Rails is all the rage these days, but you
compromise on your past investment, if you’re a
Java shop: developer and IT team skills, training, app
servers, the great JVM platform, third-party
libraries...
Can’t we leverage Groovy and proven technologies
like Spring and Hibernate to bring the “Convention
over Configuration” paradigm on the Java platform,
without compromising on your investment?
An Overview of Grails
●
An MVC framework
●
Follows the principles popularised by Rails
●
CoC – Convention over Configuration
●
DRY – Don't Repeat Yourself
●
All the goodness of Rails + all the assets
available in Java
The Stack
Java Platform
...and a few more
●
Jetty/Tomcat as containers during
development cycle
●
HSQLDB as DB for quick development
●
Basically, a full development stack to
code, compile, test and run an
application
Case Study: Sky.com
UK's entertainment and communications company
operating a multi-channel television service with
9.4+ millions customers across UK & Ireland
Whiteboard Whiteboard
Projector Projector
Table Table
static constraints = {
name()
category()
}
Persistence
●
Supported by Hibernate at the backend
●
Dynamic Finders
●
Asset.list()
●
Asset.findAllByCategory('Table')
●
Raw HQL queries
●
Asset.findAll(”from Asset a where a.category
=?”, ['Table'])
●
Constraints
●
nullable, size, email, blank, inList...
Creating the controller
●
>grails create-controller Asset
●
Creates a controller class named
AssetController in the controller folder
●
A controller can have many actions
Controllers
●
Located in the controller directory, with
names ending with xxxController
●
Easy data binding using params
●
asset.properties = params
●
A couple of useful methods:
●
redirect, forward, flash...
Scaffolding...
●
We'll keep things simple through the use
of scaffolding...