agile web development with groovy & grails
DESCRIPTION
An introductionary presentation for Java Developers about the dynamic language Groovy and the application framework Grails I have done at BearingPoint INFONOVA in June 2008.Slide 63 featured a live implementation of a demo app.TRANSCRIPT
![Page 1: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/1.jpg)
Agile Web Development with Groovy & Grails
![Page 2: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/2.jpg)
Groovy
![Page 3: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/3.jpg)
3© 2008 BearingPoint, Inc.
Groovy
Why?
![Page 4: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/4.jpg)
4© 2008 BearingPoint, Inc.
Groovy
Java Jobs
![Page 5: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/5.jpg)
5© 2008 BearingPoint, Inc.
Groovy
Java EE Jobs
![Page 6: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/6.jpg)
6© 2008 BearingPoint, Inc.
Groovy
Ruby On Rails Jobs
![Page 7: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/7.jpg)
7© 2008 BearingPoint, Inc.
Groovy
JSR 241
![Page 8: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/8.jpg)
8© 2008 BearingPoint, Inc.
Groovy
„Java-stylish with a Ruby-esque feeling“
![Page 9: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/9.jpg)
9© 2008 BearingPoint, Inc.
Groovy
„Groovy is not a replacement for the Java programming language; it‘s a complement to that language“
Richard Monson-Haefel, award winning author & technical analyst
![Page 10: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/10.jpg)
10
© 2008 BearingPoint, Inc.
Groovy
GroovyBeans
class GroovyBean {String name
}
![Page 11: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/11.jpg)
11
© 2008 BearingPoint, Inc.
Groovy
Autoboxing
def b = new GroovyBean()b.name = “groovy bean“
![Page 12: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/12.jpg)
12
© 2008 BearingPoint, Inc. 12
Groovy
Duck Typing„When I see a bird that walks like a
duck and swims like a duck and quacks like a duck, I call that bird a duck.“Poem by James Whitcomb Riley
![Page 13: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/13.jpg)
13
© 2008 BearingPoint, Inc.
Groovy
Expressiveness
![Page 14: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/14.jpg)
14
© 2008 BearingPoint, Inc.
Groovy
Java:java.net.URLEncoder.encode(“a b“);
Groovy:URLEncoder.encode ‘a b‘
![Page 15: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/15.jpg)
15
© 2008 BearingPoint, Inc.
Groovy
GStrings
![Page 16: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/16.jpg)
16
© 2008 BearingPoint, Inc.
Groovy
def name = “world“def message = “Hello ${name}“
![Page 17: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/17.jpg)
17
© 2008 BearingPoint, Inc.
Groovy
def text = “““Ein längerer Stringmit Zeilenumbrüchen
“““
![Page 18: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/18.jpg)
18
© 2008 BearingPoint, Inc.
Groovy
Native Lists, Maps, Regex
![Page 19: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/19.jpg)
19
© 2008 BearingPoint, Inc.
Groovy
def aList = []
def myList = [22,55,33]
Lists
![Page 20: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/20.jpg)
20
© 2008 BearingPoint, Inc.
Groovy
def emptyMap = [:]
def myMap = [“name“: “Max“, “age“ : “33“ ]
Maps
![Page 21: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/21.jpg)
21
© 2008 BearingPoint, Inc.
Groovy
myMap.name == “Max“
myMap[“age“] == “33“
Maps
![Page 22: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/22.jpg)
22
© 2008 BearingPoint, Inc.
Groovy
“cheesecheese“ =~ “cheese“ “cheesecheese“ =~ /cheese/
“potatoe“ ==~ /potatoe?/ “potato“ ==~ /potatoe?/
Regular Expressions
![Page 23: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/23.jpg)
23
© 2008 BearingPoint, Inc.
Groovy
Loopsfor (int i=0;i<6;i++) {}
for (i in 0..9) {}
def list = [1, 2, 3]for (i in list) {}
10.times {}
![Page 24: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/24.jpg)
24
© 2008 BearingPoint, Inc.
Groovy
Closures
def myClosure = { /* do something */}
![Page 25: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/25.jpg)
25
© 2008 BearingPoint, Inc.
Groovy
[3,1,2].each { print “value:“+it}
![Page 26: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/26.jpg)
26
© 2008 BearingPoint, Inc. 26
Groovy
Buildersdef xml = new groovy.xml.MarkupBuilder()
xml.authors {
author(name:‘Stephen King‘) {
book(title:‘The Shining‘)
book(title:‘The Stand‘)
}
author(name:‘James Patterson‘) {
book(title:‘Along Came a Spider‘)
}
}
![Page 27: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/27.jpg)
27
© 2008 BearingPoint, Inc. 27
Groovy
Builders<authors>
<author name=“Stephen King“>
<book title=“The Shining“ />
<book title=“The Stand“ />
</author>
<author name=“James Patterson“>
<book title=“Along Came a Spider“ />
<author>
<authors>
![Page 28: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/28.jpg)
28
© 2008 BearingPoint, Inc.
Groovy
The Groovy Truth
if (myString != null && myString.length() > 0) {myMethod(myString);}
if (myString) myMethod(myString)
![Page 29: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/29.jpg)
29
© 2008 BearingPoint, Inc.
Groovy
Save DereferencingLong id=null;if (session.getAttribute(“user“) != null) {id = ((User) session.getAttribute(“user“)).getId();}
def id = session.user?.id
![Page 30: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/30.jpg)
30
© 2008 BearingPoint, Inc.
Groovy
Meta Class Concept
![Page 31: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/31.jpg)
31
© 2008 BearingPoint, Inc. 31
Groovy
IDE Integration
![Page 32: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/32.jpg)
32
© 2008 BearingPoint, Inc.
Groovy
Domain Specific Language (DSL)
![Page 33: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/33.jpg)
33
© 2008 BearingPoint, Inc.
Groovy
Java:public class RecursiveFileReading {
public static void main(String[] args) { printAllFiles(new File(".")); } public static final void printAllFiles(File root) { File[] allChildren = root.listFiles(); for (File child : allChildren) { if (child.isDirectory()) { RecursiveFileReading.printAllFiles(child); } else { System.out.println(child.toString()); } } }}
![Page 34: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/34.jpg)
34
© 2008 BearingPoint, Inc.
Groovy
Groovy:groovy -e “new File(‘.‘).eachFileRecurse { println it }“
![Page 35: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/35.jpg)
35
© 2008 BearingPoint, Inc.
Groovy
„There is a value for learning Groovy for its own sake. It will open your mind...“
![Page 36: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/36.jpg)
Grails
![Page 37: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/37.jpg)
37
© 2008 BearingPoint, Inc.
Grails
Rapid Application Develoment(RAD)
![Page 38: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/38.jpg)
38
© 2008 BearingPoint, Inc.
Grails
Full Stack Framework
![Page 39: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/39.jpg)
39
© 2008 BearingPoint, Inc.
Grails
Convention Over Configuration(CoC)
![Page 40: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/40.jpg)
40
© 2008 BearingPoint, Inc.
Grails
RESTfullRepresentational State Transfer
![Page 41: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/41.jpg)
41
© 2008 BearingPoint, Inc.
Grails
GET
![Page 42: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/42.jpg)
42
© 2008 BearingPoint, Inc.
Grails
POST
![Page 43: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/43.jpg)
43
© 2008 BearingPoint, Inc.
Grails
PUT
![Page 44: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/44.jpg)
44
© 2008 BearingPoint, Inc.
Grails
DELETE
![Page 45: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/45.jpg)
45
© 2008 BearingPoint, Inc.
Grails
HEAD
![Page 46: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/46.jpg)
46
© 2008 BearingPoint, Inc.
Grails
OPTIONS
![Page 47: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/47.jpg)
47
© 2008 BearingPoint, Inc.
Grails
http://localhost:8080/application/user/profile/123
Controller IDAction
RESTfull
![Page 48: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/48.jpg)
48
© 2008 BearingPoint, Inc.
Grails
DRY Paradigm(Don‘t Repeat Yourself)
![Page 49: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/49.jpg)
49
© 2008 BearingPoint, Inc.
Grails
Leverages existing hardware
Leverages existing Java/Framework knowledge
![Page 50: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/50.jpg)
50
© 2008 BearingPoint, Inc.
Grails
Components
Java Virtual Machine
Java Language
Java EE
JDK
Grails
![Page 51: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/51.jpg)
51
© 2008 BearingPoint, Inc.
Grails
UI, AJAX & RIA Frameworks
GWTYUI
![Page 52: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/52.jpg)
52
© 2008 BearingPoint, Inc.
Grails
Plugin API JSF
Struts
JMS
ACEGI/Spring Security, JSecurity
OpenID
Functional Testing (Canoo WebTest)
Apache Axis 2, XFire
![Page 53: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/53.jpg)
53
© 2008 BearingPoint, Inc.
Grails
GORMGroovy Object-Relational Mapping
![Page 54: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/54.jpg)
54
class Book { String title}
© 2008 BearingPoint, Inc.
Grails
GORM
![Page 55: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/55.jpg)
55
class Book {String author String title Date releaseDate
static constraints = { author(blank:false, size:2..30) releaseDate(nullable: true) }
}
© 2008 BearingPoint, Inc.
Grails
GORM
![Page 56: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/56.jpg)
56
def book = new Book()
book.author = “author A“book.title = “title 1“
book.save()
© 2008 BearingPoint, Inc.
Grails
GORM
![Page 57: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/57.jpg)
57
def book = new Book()
book.author = “author A“book.title = “title 1“
if (book.save()) {/* successfull flow */} else {/* error flow */}
© 2008 BearingPoint, Inc.
Grails
GORM
![Page 58: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/58.jpg)
58
© 2008 BearingPoint, Inc.
Grails
(Dynamic) Finders
def macBook = Book.get(1)
def macBook = Book.findByTitle(“MacBook“)
def macBook = Book.findByTitleAndAuthor(“MacBook“, “Apple“)
![Page 59: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/59.jpg)
59
<h1>Book list</h1><table> <tr> <th>Title</th> <th>Author</th> </tr><g:each in="${books}"> <tr> <td>${it.title}</td>
<td>${it.author}</td> </tr>
</g:each> </table>
© 2008 BearingPoint, Inc.
Grails
Groovy Server Pages (GSP)
![Page 60: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/60.jpg)
60
<g:if test="${name == 'fred'}"> Hello Fred!</g:if><g:else> Hello ${name}! Do I know you?</g:else>
© 2008 BearingPoint, Inc.
Grails
Groovy Server Pages (GSP)
![Page 61: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/61.jpg)
61
<g:datePicker name="myDate" value="${new Date()}"
precision="day" years="${1930..1970}"/>
© 2008 BearingPoint, Inc.
Grails
Groovy Server Pages (GSP)
![Page 62: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/62.jpg)
62
© 2008 BearingPoint, Inc.
Grails
Scaffolding
Dynamic Scaffolding
Static Scaffolding
![Page 63: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/63.jpg)
63
© 2008 BearingPoint, Inc.
Grails
How does it look like?
![Page 64: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/64.jpg)
64
© 2008 BearingPoint, Inc.
Grails
Success Stories?
![Page 65: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/65.jpg)
65
© 2008 BearingPoint, Inc.
Grails
![Page 66: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/66.jpg)
66
© 2008 BearingPoint, Inc.
Grails
![Page 67: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/67.jpg)
67
© 2008 BearingPoint, Inc.
Grails
![Page 68: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/68.jpg)
68
© 2008 BearingPoint, Inc.
Grails
![Page 69: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/69.jpg)
69
© 2008 BearingPoint, Inc.
Grails
http://groovy.codehaus.org/
http://www.grails.org
![Page 70: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/70.jpg)
70
© 2008 BearingPoint, Inc.
Grails
Dirk König - Groovy In ActionManning, 2007
Graeme Keith Rocher - The Definitive Guide To GrailsApress, 2006
![Page 71: Agile Web Development with Groovy & Grails](https://reader034.vdocuments.us/reader034/viewer/2022052504/55281f40550346bc588b467b/html5/thumbnails/71.jpg)