0% found this document useful (0 votes)
13 views40 pages

TriJUG Getting Started With Grails

Uploaded by

scbd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views40 pages

TriJUG Getting Started With Grails

Uploaded by

scbd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Getting Started with

Grails
Rapid Web Development for the Java Platform

Presented at the Triangle Java Users Group


June 18th, 2007

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?

• Rapid web application development


‣ Getting things done
‣ Having fun doing it
• Full-stack MVC framework
• Open source
• Runs on the JVM

5
What (else) is Grails?

• Develop your apps in Groovy


‣ Highly-expressive
‣ Fully object-oriented
‣ Dynamic
‣ Familiar syntax
‣ Seamless Java integration
‣ JSR-241

6
Anything Else?

• Convention over configuration


‣ Opinionated software
‣ Sensible defaults
‣ Everything has a place
• DRY (Don't Repeat Yourself)

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

static belongsTo = Race


}

15
Relationship Counseling
Demo

16
Where's My Data?

• How did we get this far without a


database?
• Hooking up an external database
‣ Create schema
‣ Grant permissions
‣ Add drivers to racetrack/lib
‣ Update data source

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

• What if I need to...


‣ find all races in North Carolina?
‣ count the races longer than 4 miles?
‣ get a list of the 10 longest races?
‣ find races matching a certain pattern?
‣ list all races with registrations?

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

• Build rich clients


• Expose web services
• Secure your app
• Roll your own scaffolding
• Integrate a search engine
• Almost limitless possibilities

32
grails.org/roadmap

• Future releases (Pre 1.0)


‣ Support for JSP custom tag libraries in GSP
‣ Spring Web Flow
‣ JavaScript DSL
‣ Domain model generation from database schema
‣ JPA support

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

• Sun (JavaOne 2007)


http://www28.cplan.com/cc158/session_details.jsp?
isid=286133&ilocation_id=158-1&ilanguage=english

34
Resources

• grails.org
‣ Downloads
✦ Latest release (0.5.6)

✦ Development snapshot (0.6)

‣ User guide, tutorials, screencasts, etc.


‣ Mailing lists (grails.org/mailing+lists)

35
Resources (cont’d)
aboutGroovy.com

grails.org/grails+podcast

groovyblogs.org

36
2007 No Fluff Just Stuff

Research Triangle Software Symposium


July 20th - 22nd
Marriott RTP
nofluffjuststuff.com/sh/2007-07-raleighdurham

37
Grails eXchange 2007

October 17th - 19th


Barbican, London, UK
grails-exchange.com

38
Books

39
www.jasonrudolph.com

jason@jasonrudolph.com

40

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy