TriJUG Getting Started With Grails
TriJUG Getting Started With Grails
Grails
Rapid Web Development for the Java Platform
1
Creative Commons License
• This presentation is published under the Creative Commons Attribution Noncommercial Share
Alike License Version 2.5. (Please see http://creativecommons.org/licenses/by-nc-sa/2.5/ for
complete details.)
• You are free to reuse and modify this presentation under the following conditions. (Thanks to
Steven Devijver for providing this excellent summary of the license terms.):
‣ You don’t get compensated for providing this presentation (non-commercial).
‣ You don’t get compensated for presenting this presentation in front of your audience (non-
commercial). You are exempted from this condition if you are tutoring your colleagues.
‣ You do not charge members of your audience for a digital copy of this presentation.
‣ You are free to charge your audience for printed versions of this presentation or for the
media that contains this presentation, but only if you personally actually incur a non-
recoverable cost.
‣ You keep and do not modify the content of this license slide in the presentation (share
alike).
‣ You attribute that Jason Rudolph is the original creator and maintainer of this presentation
(attribution).
‣ If you modify the content and distribute or modify the content and show this presentation to
an audience, you are required to send your modified file to contact@jasonrudolph.com.
‣ You have the right to call yourself co-author if you modify the content of this presentation in
a non-trivial way.
‣ If you alter, transform, or build upon this work, you may distribute the resulting work only
under a license identical to this one (share alike).
2
Introduction
• Jason Rudolph
• Grails Committer
• Software Consultant
• Author
3
Agenda
• Grails? What’s that?
• Hello, Productivity
• Painless ORM (Seriously)
• Routing and Validation Made Simple
• A New Point of View
• Cool (and Groovy) Features
• Test, Deploy, Profit!
4
What is Grails?
5
What (else) is Grails?
6
Anything Else?
7
Rock-Solid Foundation
8
Let's Get Started
• Ready?
‣ Install JDK 1.4 (or higher)
‣ Set JAVA_HOME
• Set
‣ Download latest Grails release
‣ Set GRAILS_HOME
‣ Add $GRAILS_HOME/bin to your PATH
9
Hello, Grails
Demo
10
What’s
Inside?
11
Instant Gratification
Demo
12
Grails ORM (GORM)
• Zero-configuration persistence
management
• DAOs Dynamic domain class methods
‣ save ‣ find
‣ delete ‣ findAll
‣ get ‣ count
‣ list ‣ etc.
13
Relationship Counseling
14
1:n Relationships
class Race {
//...
static hasMany =
[registrations:Registration]
}
class Registration {
//...
Race race
15
Relationship Counseling
Demo
16
Where's My Data?
17
Be Persistent
Demo
18
Declaring Constraints
• Pre-packaged constraints
‣ blank ‣ matches
‣ creditcard ‣ nullable
‣ email ‣ range
‣ inList ‣ unique
‣ min ‣ url
‣ max ‣ etc.
• Custom constraints
19
Show Some Constraint!
Demo
20
Fun with URLs
http://localhost:8080/racetrack/race/show/2
21
Fun with URLs
http://localhost:8080/racetrack/race/show/2
class RaceController {
//...
def show = {
[ race : Race.get( params.id ) ]
}
//...
}
22
GSP
23
GSP
RaceController.groovy
def show = {
[ race : Race.get( params.id ) ]
}
views/race/show.gsp
<g:each var="r" in="${race.registrations}">
<li>
<g:link controller="registration"
action="show" id="${r.id}">${r.name}
</g:link>
</li>
</g:each>
24
Groogle?
25
Get Dynamic
Dynamic Finder Methods
26
Get Dynamic
Demo
27
Putting It to the Test
• Unit testing
‣ GroovyTestCase created for each class
‣ grails test-app executes all test cases
• Functional testing
‣ Canoo Web Test
‣ grails generate-webtest
‣ grails run-webtest
28
Deployment
grails war
29
Beyond the Finish Line
• Services
‣ transactional
‣ non-transactional
• Java Integration (src/java)
• Rich (and Friendly) Tag Libraries
• Ajax
30
Still More to Explore
• Custom URL Mapping
• Alternate Domain Implementations
‣ Using Hibernate XML for legacy schemas
‣ EJB3 entity beans
• Command Objects for Forms
• Job Scheduling
• Layouts & CSS
31
grails.org/plugins
32
grails.org/roadmap
33
Important Companies
Talking About Grails
• Oracle
http://www.oracle.com/technology/pub/articles/grall-
grails.html
• BEA
http://dev2dev.bea.com/pub/a/2006/10/introduction-
groovy-grails.html
34
Resources
• grails.org
‣ Downloads
✦ Latest release (0.5.6)
35
Resources (cont’d)
aboutGroovy.com
grails.org/grails+podcast
groovyblogs.org
36
2007 No Fluff Just Stuff
37
Grails eXchange 2007
38
Books
39
www.jasonrudolph.com
jason@jasonrudolph.com
40