SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
Groovy and Grails

      Prabhu
prabhu@prabhu-s.com
Groovy
                         • is an agile and dynamic language for JVM
                         • Features inspired from Python, Ruby …
                         • Seamless integration with all existing
                         Java classes and libraries.


• Groovysh and GroovyConsole
• Can run on .Net 2.0 using IKVM
• Latest version 1.5
• http://groovy.codehaus.org
Features
•   Closures
•   Dynamic Methods
•   List & Maps
•   Better XML/Swing Capabilities
Closure
• Statements enclosed within curly braces
  “{}“
• Can be passed around like variables
• Return value either using return
  keyword or the value of last executed
  statement.
Closure (Contd)
square = { it * it }
square (4)
Output = 16

“it” implicit parameter representing the
   passed value.
Closure (Contd)
square {
   it * it
   return 3
}

square (4)
Output = 3 (Since there is an explicit
  return statement!)
Closure (Contd)
square = { param1 ->
   param1 * param1
}

square (3)
Output = 9
Param1 – Named parameter
Factorial using closures
fact = 1               fact = 1
for (i in 2..5) {      (2..5).each {
                         number ->
   fact *= i
                         fact *= number
}                      }
print fact             print fact

                       // (2..5) = Range
Factorial again!
fact = 1
2.upto(5) { num ->
  fact *= num
}
print fact

// Numbers are treated as object.
• upto method generates all number objects
• To each object, the closure gets passed
   around!
Generic Factorial
fact = 1
fun = { n->
       2.upto(n) { num ->
       fact *= num
  }
}

fun(5)
print fact
Dynamic methods
class webcamp {
  def haveTea() {
     println quot;Time for teaquot;
  }
}

camp = new webcamp()
camp.haveTea()
Dynamic methods (Contd)
• Add a new method “haveSamosa”
class webcamp {
   def haveTea() {
         println quot;Time for tea“
   }
}
camp = new webcamp()
camp.haveTea()

webcamp.metaClass.haveSamosa = { ->
  println quot;Have Samosa alsoquot;
}

camp = new webcamp() // Create a fresh object since the class has
   changed!
camp.haveSamosa()
Lists and Maps
• Like python
List = [2,3,4]
Map = [„a‟ : 2, „b‟ : new Date()]
Grails
• Web Framework inspired by RoR
• Latest version is 1.0.1.
   – The one in the DVD is 1.0 and doesn‟t run cleanly in
     windows!
• Grails = Spring MVC 2.5.1 + Hibernate 3 +
  SiteMesh 2.3
• Newbie‟s are unaware that Grails is full and full
  Spring!
• Provides several commands to auto generate
  code.
• Comes bundled with HSQLDB.
Create your first app
• Set environmental variables
  GRAILS_HOME and PATH
• grails create-app firstapp
Directory Structure

                      Controllers
        Domain



            Views


            Sources

            Test cases


            J2EE Web Appln.
First app Demo
• grails create-domain-class <name>
• grails create-controller <name>
• grails run-app (Starts inbuilt Jetty 6.1.4
  server)
• Visit http://localhost:8080/firstapp
• Demo
Features
• Both gsp and jsp are supported.
• Specify constraints
static constraints = {
      username (minLength : 3, maxLength: 8, blank:false)
      password(minLength : 5, maxLength:9, blank:false)
   }


• Specify Optional fields
static optionals = [“middle_name”, “addr2”]
Features (Contd)
• Dynamic finder methods
def search = {
   render(view : „list‟,
        model : [userList :
                      User.findAllByUsernameLike (
                           „%‟ + params.username + „%‟)
                 ]
        )
}

• User.findAllByUsernameLikeAndPassword
  Like
Features (Contd)
• Create Advanced Search criteria using
  Hibernate Criteria Builder.
def criteria = User.createCriteria() // Dynamic method
def results = criteria {
   and (
          like („username‟ , „%‟ + params.username + „%‟)
          le(„age‟, params.age)
          )
}
Render(view:‟list‟, model:[userList : results])
Features (Contd)
• Flash scope - Data will be stored as
  name-value pairs for current request
  and the next request.
• Create custom tags just by creating a
  new file in grails-
  app/taglib/<name>TagLib.groovy
Features (Contd)
• AJAX Support
  – Supports prototype, YUI, DOJO
  – Use render method in your groovy code to
    render text, HTML, JSON or OpenRico
    Response XMLs
• Plays nicely with flex
  – Simply add this
    static expose = [“flex-remoting”]
  – Automatic flex based CRUD generation and
    Domain class to AS3 compilation coming up!
Features (Contd)
• Plays nicely with EJB
  – http://www.infoq.com/articles/grails-ejb-
    tutorial
• Has lots of plugins already!
  – grails install-plugin <name>
  – grails create-plugin <name>
Scalability
• Thanks to Spring and Hibernate, Grails
  is highly scalable and already enterprise
  ready!
RoR Competition?
• No.
  – Instead going to compete with Java based
    frameworks like struts 2, JSF, Seam.
Should I learn?
• If you are a Java guy, then yes.
• Companies like Oracle have already
  started showing full support!
Thanks



Q&A

Contenu connexe

Tendances

Handling 20 billion requests a month
Handling 20 billion requests a monthHandling 20 billion requests a month
Handling 20 billion requests a month
Dmitriy Dumanskiy
 

Tendances (20)

Groovyノススメ
GroovyノススメGroovyノススメ
Groovyノススメ
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJSFunctional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
 
Understanding the nodejs event loop
Understanding the nodejs event loopUnderstanding the nodejs event loop
Understanding the nodejs event loop
 
Declarative Infrastructure Tools
Declarative Infrastructure Tools Declarative Infrastructure Tools
Declarative Infrastructure Tools
 
Tweaking performance on high-load projects
Tweaking performance on high-load projectsTweaking performance on high-load projects
Tweaking performance on high-load projects
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
 
Handling 20 billion requests a month
Handling 20 billion requests a monthHandling 20 billion requests a month
Handling 20 billion requests a month
 
JVM performance options. How it works
JVM performance options. How it worksJVM performance options. How it works
JVM performance options. How it works
 
Talk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe ConversetTalk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe Converset
 
Silent Revolution by Max Voronoy (Senior Consultant, Engineering, Globallogic)
Silent Revolution by Max Voronoy (Senior Consultant, Engineering, Globallogic)Silent Revolution by Max Voronoy (Senior Consultant, Engineering, Globallogic)
Silent Revolution by Max Voronoy (Senior Consultant, Engineering, Globallogic)
 
Go Containers
Go ContainersGo Containers
Go Containers
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftReactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwift
 
Graphql with Flamingo
Graphql with FlamingoGraphql with Flamingo
Graphql with Flamingo
 
Cascadia.js: Don't Cross the Streams
Cascadia.js: Don't Cross the StreamsCascadia.js: Don't Cross the Streams
Cascadia.js: Don't Cross the Streams
 
Scalable Angular 2 Application Architecture
Scalable Angular 2 Application ArchitectureScalable Angular 2 Application Architecture
Scalable Angular 2 Application Architecture
 
Async Microservices with Twitter's Finagle
Async Microservices with Twitter's FinagleAsync Microservices with Twitter's Finagle
Async Microservices with Twitter's Finagle
 
Luis Atencio on RxJS
Luis Atencio on RxJSLuis Atencio on RxJS
Luis Atencio on RxJS
 
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
Timur Shemsedinov "Пишу на колбеках, а что... (Асинхронное программирование)"
 
Golang concurrency design
Golang concurrency designGolang concurrency design
Golang concurrency design
 
The What, Why And How of ClojureScript
The What, Why And How of ClojureScriptThe What, Why And How of ClojureScript
The What, Why And How of ClojureScript
 

Similaire à Groovy and Grails talk

名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
Tsuyoshi Yamamoto
 
Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
Chihoon Byun
 

Similaire à Groovy and Grails talk (20)

What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?What's up with Prototype and script.aculo.us?
What's up with Prototype and script.aculo.us?
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
 
Getting Started with WebGL
Getting Started with WebGLGetting Started with WebGL
Getting Started with WebGL
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
 
Groovy a Scripting Language for Java
Groovy a Scripting Language for JavaGroovy a Scripting Language for Java
Groovy a Scripting Language for Java
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
 
.gradle 파일 정독해보기
.gradle 파일 정독해보기.gradle 파일 정독해보기
.gradle 파일 정독해보기
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extreme
 
Groovy
GroovyGroovy
Groovy
 

Dernier

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
dollysharma2066
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Anamikakaur10
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
allensay1
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
amitlee9823
 

Dernier (20)

The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLWhitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
Whitefield CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
 
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business Potential
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 

Groovy and Grails talk

  • 1. Groovy and Grails Prabhu prabhu@prabhu-s.com
  • 2. Groovy • is an agile and dynamic language for JVM • Features inspired from Python, Ruby … • Seamless integration with all existing Java classes and libraries. • Groovysh and GroovyConsole • Can run on .Net 2.0 using IKVM • Latest version 1.5 • http://groovy.codehaus.org
  • 3. Features • Closures • Dynamic Methods • List & Maps • Better XML/Swing Capabilities
  • 4. Closure • Statements enclosed within curly braces “{}“ • Can be passed around like variables • Return value either using return keyword or the value of last executed statement.
  • 5. Closure (Contd) square = { it * it } square (4) Output = 16 “it” implicit parameter representing the passed value.
  • 6. Closure (Contd) square { it * it return 3 } square (4) Output = 3 (Since there is an explicit return statement!)
  • 7. Closure (Contd) square = { param1 -> param1 * param1 } square (3) Output = 9 Param1 – Named parameter
  • 8. Factorial using closures fact = 1 fact = 1 for (i in 2..5) { (2..5).each { number -> fact *= i fact *= number } } print fact print fact // (2..5) = Range
  • 9. Factorial again! fact = 1 2.upto(5) { num -> fact *= num } print fact // Numbers are treated as object. • upto method generates all number objects • To each object, the closure gets passed around!
  • 10. Generic Factorial fact = 1 fun = { n-> 2.upto(n) { num -> fact *= num } } fun(5) print fact
  • 11. Dynamic methods class webcamp { def haveTea() { println quot;Time for teaquot; } } camp = new webcamp() camp.haveTea()
  • 12. Dynamic methods (Contd) • Add a new method “haveSamosa” class webcamp { def haveTea() { println quot;Time for tea“ } } camp = new webcamp() camp.haveTea() webcamp.metaClass.haveSamosa = { -> println quot;Have Samosa alsoquot; } camp = new webcamp() // Create a fresh object since the class has changed! camp.haveSamosa()
  • 13. Lists and Maps • Like python List = [2,3,4] Map = [„a‟ : 2, „b‟ : new Date()]
  • 14. Grails • Web Framework inspired by RoR • Latest version is 1.0.1. – The one in the DVD is 1.0 and doesn‟t run cleanly in windows! • Grails = Spring MVC 2.5.1 + Hibernate 3 + SiteMesh 2.3 • Newbie‟s are unaware that Grails is full and full Spring! • Provides several commands to auto generate code. • Comes bundled with HSQLDB.
  • 15. Create your first app • Set environmental variables GRAILS_HOME and PATH • grails create-app firstapp
  • 16. Directory Structure Controllers Domain Views Sources Test cases J2EE Web Appln.
  • 17. First app Demo • grails create-domain-class <name> • grails create-controller <name> • grails run-app (Starts inbuilt Jetty 6.1.4 server) • Visit http://localhost:8080/firstapp • Demo
  • 18. Features • Both gsp and jsp are supported. • Specify constraints static constraints = { username (minLength : 3, maxLength: 8, blank:false) password(minLength : 5, maxLength:9, blank:false) } • Specify Optional fields static optionals = [“middle_name”, “addr2”]
  • 19. Features (Contd) • Dynamic finder methods def search = { render(view : „list‟, model : [userList : User.findAllByUsernameLike ( „%‟ + params.username + „%‟) ] ) } • User.findAllByUsernameLikeAndPassword Like
  • 20. Features (Contd) • Create Advanced Search criteria using Hibernate Criteria Builder. def criteria = User.createCriteria() // Dynamic method def results = criteria { and ( like („username‟ , „%‟ + params.username + „%‟) le(„age‟, params.age) ) } Render(view:‟list‟, model:[userList : results])
  • 21. Features (Contd) • Flash scope - Data will be stored as name-value pairs for current request and the next request. • Create custom tags just by creating a new file in grails- app/taglib/<name>TagLib.groovy
  • 22. Features (Contd) • AJAX Support – Supports prototype, YUI, DOJO – Use render method in your groovy code to render text, HTML, JSON or OpenRico Response XMLs • Plays nicely with flex – Simply add this static expose = [“flex-remoting”] – Automatic flex based CRUD generation and Domain class to AS3 compilation coming up!
  • 23. Features (Contd) • Plays nicely with EJB – http://www.infoq.com/articles/grails-ejb- tutorial • Has lots of plugins already! – grails install-plugin <name> – grails create-plugin <name>
  • 24. Scalability • Thanks to Spring and Hibernate, Grails is highly scalable and already enterprise ready!
  • 25. RoR Competition? • No. – Instead going to compete with Java based frameworks like struts 2, JSF, Seam.
  • 26. Should I learn? • If you are a Java guy, then yes. • Companies like Oracle have already started showing full support!