0% found this document useful (0 votes)
152 views

Prototyping With Grails

This document provides an overview of prototyping applications with Grails, a web application framework for the JVM. It discusses Grails' history, stack, and conventions over configuration approach. Examples are given of companies using Grails like LinkedIn. The basics of creating a Grails application are demonstrated, including generating the domain class, controller, and views using scaffolding. Key aspects of Grails like the MVC architecture and integration with technologies like Spring and Hibernate are summarized.

Uploaded by

MOSC2010
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Prototyping With Grails

This document provides an overview of prototyping applications with Grails, a web application framework for the JVM. It discusses Grails' history, stack, and conventions over configuration approach. Examples are given of companies using Grails like LinkedIn. The basics of creating a Grails application are demonstrated, including generating the domain class, controller, and views using scaffolding. Key aspects of Grails like the MVC architecture and integration with technologies like Spring and Hibernate are summarized.

Uploaded by

MOSC2010
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Prototyping with Grails

Mohd Suhaizal
Software Engineer
Jaringan Data Sdn Bhd

”Make everything as simple as possible, but


not simpler” - Albert Einstein
Session Contents

The Java development scenario

The history of Grails

Grails' stack

Who's using it?

Let's get started...
Java Development Scenario

JDK

Web container/Application server

Build system

Application stack

Persistence framework

Web framework

Testing framework

Logging framework.....
Java Development Scenario

Each requires configuration

As development progresses, more XML to
configure....

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

SiteMesh Spring Hibernate JUnit

Java Language JDK

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

Rebuilds the CMS for its home page using Groovy


and Grails

* Case study by SpringSource


Case Study: Wired.com
The online arm of Wired Magazine, is a cutting edge
guide covering how technology is changing the world

The Product Reviews section is developed from


scratch using Groovy and Grails

* Case study by SpringSource


Use Cases: LinkedIn
A business oriented social networking site, mainly used for
professional networking. It has 70+ millions users, over 200
countries and territories worldwide.

Re-used its existing Spring backend


A Simple Inventory Tracking

An asset is always located at a location

Whiteboard Whiteboard

Projector Projector
Table Table

ROOM 101 ROOM 102


Getting Started...

Download and install Groovy & Grails

Groovy – groovy.codehaus.org

Grails - www.grails.org

Set up environment variables for Groovy
& Grails

GROOVY_HOME

GRAILS_HOME
Grails Command Line

Getting the list of available commands

>grails help

Commonly used ones (YMMV):

grails create-app

grails create-domain-class

grails create-controller

grails generate-all

grails test-app

grails run-app

grails war
The First Step

grails create-app

Creates application skeleton with predefined
layouts
The MVC Story

Model – the domain classes representing
the problem domain, as POGO

View – the view rendering portion
written as GSP

Controller – control flows, manipulates
the model and delegating the result to
the view through actions
Creating the model

>grails create-domain-class Asset

Creates a groovy class and file
representing the domain
Asset.groovy
class Asset{
String name
String category

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...

def scaffold = true


Views

Each controller has its own folder
representing its views – CoC

AssetController - Asset

Each action has its own GSP.

list - list.gsp

Useful Grails tag libraries available

link, each, if...

Templating with SiteMesh
What I didn't touched...

Grails plugins

Custom taglibs

Using AJAX

Creating services

Creating & running tests

...

You might also like