SlideShare a Scribd company logo
GRAILS RAPID WEB APPLICATION DEVELOPMENT MADE EASY
About: Sven Haiges Actionality Deutschland GmbH Senior Java Developer Diplom-Informatiker (FH), MBA My personal framework evolution: Struts, JSF, Spring MVC, GRAILS Since Juli 2006:  Grails Podcast, Grails Screencasts
Goals What is Grails & how do I create my first Grails app? What are the powerful cornerstones of Grails? Which features does Grails provide out of the box? Next Steps @ Home/Work
Agenda Basics Foundations MVC Features Roadmap Your Next Steps
Grails Basics
Grails MVC Grails is an MVC Web Framework Inspired by Ruby on Rails Uses the powerful Groovy Scripting Language Convention Over Configuration Don't Repeat Yourself (DRY)
Grails History & Team Started by Groovy enthusiasts: Guillaume LaForge, Steven Devijver and Graeme Rocher (current project lead) 0.1 was out March 29th, 2006 Current  Team: Graeme Rocher, Marc Palmer, Dierk Koenig, Steven Devijer, Jason Rudolph, Sven Haiges...  YOU!
Using Grails Standalone Configuration details are hidden 0..100 in no time! Integrate with existing applications Still use the flexibility of Grails for existing DB-Schemas, HBM-Mappings, Spring Configuration, etc. Pimp your app!
Powerful Foundations Foundations Groovy: 1 st  class integration with Java Platform and all Java Code you have ever written! Spring: IoC, Spring MVC, WebFlow, ... Hibernate: powerful   p ersistence Layer SiteMesh: flexible layout framework
Installing Grails No previous Groovy installation needed, just a Java VM 1.4+ (but does not hurt :-) grails.org/Installation Download, extract, set GRAILS_HOME, add bin to PATH, run it! Type „grails“ to verify it works
Your First Grails App „ grails create-app“ „ cd appName” „ grails run-app“ „ grails create-domain-class“, edit class „ grails generate-all“ „ grails run-app“
Grails Foundations
Spring Spring Framework is used to hold everything together You can specify your own Spring Beans for injection into Controllers, Services, Jobs in spring/resources.xml Good to know: a Grails app is an Spring MVC app... Spring Webflow to be used in future
Hibernate Hibernate is the de facto standard for O/R Mapping Grails maps your Domain Classes automatically, even creates and exports the schema to the database 1:n & m:n  supported! Great flexibility: use your own HBM files for legacy database schemas!
SiteMesh SiteMesh is a powerful Layout Framework and integrated into Grails grails-app/views/layout/main.gsp is the standard layout file This meta element in a head of a gsp file links it with the “main” layout: < meta  name = &quot;layout&quot;  content = &quot;main&quot;  />
Grails Philosophy Reuse (see foundations) No “reinventing the wheel” Coding by Convention without being locked into a single solution! Domain-Centric, not DB-Centric DRY
Grails MVC
Model Above is a Domain Class .groovy files living in grails-app/domain Persistent id, version, equals, hashCode, toString is generated automatically, but can be overridden class  Book { String title }
Model You will typically use this convenience target to create Domain Classes Will ask you for the name, make it uppercase if you forget > grails create-domain-class
Model 1:1 mapping with Author Specify the “owning side” with this class Book { Author author String title } class Book { def belongsTo = Author Author author String title }
Model 1:n mapping: Author has many Books Property “books” created automatically Same for adder method: class Author { def hasMany = [ books : Book ] String name } author.addBook(new Book(title:'Grails')) author.save()
Model m:n possible, too! BelongsTo defines “owning side”  class Book { def belongsTo = Author def hasMany = [authors:Author] } class Author { def hasMany = [books:Book] }
Model Constraints defined via constraints closure Affects generation of views, too! class User { String login String password String email Date age static constraints  = { login(length:5..15,blank:false,unique:true) password(length:5..15,blank:false) email(email:true,blank:false) age(min:new Date(),nullable:false) } }
Model Dynamic Finder Methods def results = Book.findByTitle(&quot;The Stand&quot;) results = Book.findByTitleLike(&quot;Harry Pot%&quot;) results = Book.findByReleaseDateBetween( firstDate, secondDate ) results = Book.findByReleaseDateGreaterThan( someDate ) You can also use Query by Example (QBE) the Hibernate Criteria Builder, or direct HQL queries!
Model Database configuration is done in  grails-app/conf directory DevelopmentDataSource.groovy ProductionDataSource.groovy TestDataSource.groovy If you hit “grails run-app” the dev datasource is the default
Model “grails war” creates your deployment war file with the  production  datasource class  DevelopmentDataSource { boolean  pooling =  true // one of 'create', 'create-drop','update' //String dbCreate = &quot;create-drop&quot;  String url =  &quot;jdbc:postgresql://localhost:5432/act_dev&quot; String driverClassName =  &quot;org.postgresql.Driver&quot; String username =  &quot;dev&quot; String password =  &quot;devpw&quot; def  logSql =  true   //enable logging of SQL generated by Hibernate }
Model BootStrap files are picked up at startup and can be used to create initial (test) data class  CompanyBootStrap { def  init = { servletContext -> //Delete all data in the tables that we work on Company.executeUpdate( &quot;delete Company&quot; )  //now create the test data Company c1 =  new  Company(name: 'bmw' ) c1.addUser( new  User(name: 'herbert' , admin: true , ...)) .save() }  ...
View Groovy Server Pages(GSP) or  JavaServer Pages (JSP) TagLibs for both, but GSP is groovin' All views are in the grails-app/views directory Generate views for your domain class: “grails generate-views”
View Example GSP / uses “main” Layout < html > < head > < meta  name = &quot;layout&quot;  content = &quot;main&quot;  /> < title > BlogEntry List </ title > </ head > < body > < div  class = &quot;nav&quot; > < span  class = &quot;menuButton&quot; > < g:link  controller = &quot;authentication&quot;  action = &quot;viewControllers&quot;  > Home </ g:link ></ span > < span  class = &quot;menuButton&quot; >< g:link  action = &quot;create&quot; > New BlogEntry </ g:link ></ span > </ div > < div  class = &quot;body&quot; > ... </ div > ...
View Dynamic Tag Libraries Tags are  fun  again! “grails create-taglib” A plain *TagLib.groovy file in grails-app/taglib As with GSPs & Controllers: no server restart!
View TagLib example  (“simple” tag) class  MyTagLib { includeJs = { attrs -> out <<  &quot;<script src='scripts/ ${attrs['script']} .js' />&quot; } }   OutputStream is available via “out” All attributes are in the attrs map Usage of GStrings keeps tags readable
View Logical and iterative tags just as easy. You can even call tags as “methods” within GSP – here used as normal tag: <g:hasErrors bean=&quot;${book}&quot; field=&quot;title&quot;> <span class='label error'>There were errors on the book title</span> </g:hasErrors> Or as method: <span id=&quot;title&quot; class=&quot;label ${hasErrors(bean:book,field:'title','errors')}&quot;>Title</span>
View Creating markup from tags is a piece of cake: def dialog = { attrs, body -> mkp { div('class':'dialog') { body() } } } Above example uses a Groovy MarkupBuilder
Controller All controllers are mapped to the Grails dispatcher servlet Create a new controller via: “grails create-controller” Or generate the controller based on an existing Domain Class: “grails generate-controller”
Controller Default Mapping Convention http://.../appName/controller/action/id Some properties automatically available flash – map stores messages for next request log -  a Log4J logger instance params – map with all request parameters request/response/servletContext etc.
Controller Example generated controller: class  AdvertisementController { def  index = { redirect(action:list,params:params) } def  list = { [ advertisementList: Advertisement.list( params ) ] } def  show = { [ advertisement : Advertisement.get( params.id ) ] } ...
Controller You can also use dynamic scaffolding: class BookController { def scaffold = Book } list/show/edit/delete/create/save/ update “dynamically” available You can still override actions “grails generate-all” creates all views and all controller actions for a domain class
Controller Grails Services can be used to encapsulate business logic Services may be injected into Controllers “grails create-service” creates a new service in grails-app/services
Controller Example Service class CountryService { def String sayHello(String name) { return &quot;hello ${name}&quot; } } Used within a controller class GreetingController { CountryService countryService def helloAction = { render(countryService.sayHello(params.name)) } }
About Scaffolding... Use it to get up to speed, have something to show and work on You will not scaffold your complete web application Learn from the generated code, tweak it to fit your individual needs
Grails Features
Auto Reloading In development mode, Grails synchronizes the current application with the server Controllers, GSPs, Tag Libraries, Domain Classes, Services, etc. This is essential for an iterative and incremental development.  Call it “agile” if you like!
Spring Integration You can put additional Spring configuration in the /spring directory and use it to configure your beans Automatic DI is available even for these beans (not just Services) Easily integrate existing (Java) functionality that was configured with Spring
Hibernate Integration You can specify your own HBM files for your domain classes. (You can even use your existing Java classes if you like) Working with legacy database schemas is getting really simple Still use all benefits like dynamic finder methods
Eclipse “Integration” Grails creates an Eclipse Project file automatically, just run  File > Import > Existing Project You'll have to tweak some file names if you use the development snapshot versions Be sure to install the Groovy Plugin: groovy.codehaus.org/Eclipse+Plugin
AJAX Grails supports AJAX with different AJAX toolkits, currently Prototype, Dojo and Yahoo Special AJAX tags can be used for asynchronous calls and form submission <div id=&quot;message&quot;></div> <g:remoteLink action=&quot;delete&quot; id=&quot;1&quot; update=&quot;message&quot;>Delete Book</g:remoteLink>
AJAX On the server side, Grails supports AJAX via the render() Method, which makes AJAX responses really easy: def time = { render(contentType:'text/xml') { time(new Date()) } } Render() supports MarkupBuilders for XML, HTML, JSON, OpenRico
Job Scheduling Grails makes using Quartz even easier, just create this (in grails-app/jobs): class  MyJob { def  cronExpression =  &quot;0,15,30,45 * * * * ?&quot; //every 15 seconds def  execute(){ println   &quot;Running job!&quot; } }
Unit & Functional Testing Both unit and functional testing supported Functional Testing uses Canoo Webtest “grails test-app” runs the unit tests “grails run-webtest” Generate a webtest with “grails generate-webtest”
Grails Roadmap
The Sandbox New Controllers Page Flows Constraints for DB-Schema creation Laszlo on Grails Mail / Messaging Integration Test DataSets Plugin-System
Roadmap 0.3 Spring 2 Web Services Service Classes M:N Mapping for GORM 0.4 DWR Support for Service Classes Pluggable Persistence Layer
Roadmap 0.5 XML-RPC for Service Classes Generation of Domain Model from DB Schema 0.6 Scaffolding of User Authentication Code Grails is user-centric,  you  define what really happens. Vote in Jira: http://jira.codehaus.org/browse/GRAILS
Your Next Steps
Learn more Download, Install, create your first app with the Quickstart Guide http://www.grails.org/Quick+Start Check out the Tutorials Section http://www.grails.org/Tutorials
Learn more Read & Work through the user guide http://www.grails.org/User+Guide Get onto the Grails user mailing list http://www.grails.org/Mailing+lists Remember: Grails is open source... The more you contribute, the more you get out in terms of learning, jobs, contacts...
Watch Currently two screencasts available Scaffolding Directory Structure http://www.grails.org/Grails+Screencasts
Listen Grails Podcast Weekly Show Grails News Grails Features Interviews Agile Development http://hansamann.podspot.de/rss
Read Out soon! By Graeme Rocher,  Grails Project Lead ISBN: 1-59059-758-3
Contribute Be part of the community Contribute a Tag! grails.org/Contribute+a+Tag Blog about Grails! Now! Answer questions on the Grails Users List! and...
Groovy & Grails Shop Buy your girlfriend one of those sexy Groovy GStrings http://tinyurl.com/y3zmos New!
GRAILS RAPID WEB APP DEVELOPMENT MADE EASY Questions? www.grails.org www.svenhaiges.de

More Related Content

PPT
Expens-O-Meter, a web based tool built using Ruby on Rails
PPTX
JavaScript : A trending scripting language
KEY
Seafox
PPT
JavaScript on Rails 튜토리얼
PDF
Create responsive websites with Django, REST and AngularJS
KEY
Making Django and NoSQL Play Nice
KEY
An Introduction to Ruby on Rails
PPT
Jasig Rubyon Rails
Expens-O-Meter, a web based tool built using Ruby on Rails
JavaScript : A trending scripting language
Seafox
JavaScript on Rails 튜토리얼
Create responsive websites with Django, REST and AngularJS
Making Django and NoSQL Play Nice
An Introduction to Ruby on Rails
Jasig Rubyon Rails

What's hot (20)

PPTX
1. java script language fundamentals
PDF
Laravel 8 export data as excel file with example
PDF
Introduction to AngularJS
ODP
Object Oriented Javascript
PDF
AngularJS Basics
DOCX
Shaping up with angular JS
PDF
Hybrid Web Applications
PPTX
JAVASCRIPT and JQUERY For Beginner
PPTX
Angular js PPT
PDF
Django Rest Framework and React and Redux, Oh My!
PPTX
Angular JS - Introduction
PPTX
AngularJS Introduction
PPTX
JavaScript Core fundamentals - Learn JavaScript Here
PDF
Integrating React.js Into a PHP Application
PPTX
AngularJS One Day Workshop
DOCX
Controller in AngularJS
DOCX
Understanding angular js $rootscope and $scope
PPTX
Why Django for Web Development
DOCX
Directives
PPTX
Angular Js Get Started - Complete Course
1. java script language fundamentals
Laravel 8 export data as excel file with example
Introduction to AngularJS
Object Oriented Javascript
AngularJS Basics
Shaping up with angular JS
Hybrid Web Applications
JAVASCRIPT and JQUERY For Beginner
Angular js PPT
Django Rest Framework and React and Redux, Oh My!
Angular JS - Introduction
AngularJS Introduction
JavaScript Core fundamentals - Learn JavaScript Here
Integrating React.js Into a PHP Application
AngularJS One Day Workshop
Controller in AngularJS
Understanding angular js $rootscope and $scope
Why Django for Web Development
Directives
Angular Js Get Started - Complete Course
Ad

Viewers also liked (6)

PPTX
Why Apps Succeed: 4 Keys to Winning the Digital Quality Game
PPTX
3 Free Tools That Will Help You Create the Right Mobile & Web Test Strategy
PPTX
A Data-Driven Approach to Testing the Right Devices, Platforms, and User Cond...
PDF
Creating applications with Grails, Angular JS and Spring Security
PPTX
Selenium Automation Like You’ve Never Seen!
PDF
Selenium and Open Source Advanced Testing
Why Apps Succeed: 4 Keys to Winning the Digital Quality Game
3 Free Tools That Will Help You Create the Right Mobile & Web Test Strategy
A Data-Driven Approach to Testing the Right Devices, Platforms, and User Cond...
Creating applications with Grails, Angular JS and Spring Security
Selenium Automation Like You’ve Never Seen!
Selenium and Open Source Advanced Testing
Ad

Similar to Grails 0.3-SNAPSHOT Presentation WJAX 2006 English (20)

PPT
Grails Introduction - IJTC 2007
ODP
Agile web development Groovy Grails with Netbeans
PPTX
Introduction to Grails Framework
PPT
Introduction To Grails
POT
intoduction to Grails Framework
ODP
SVCC Intro to Grails
PPT
JavaOne 2008 - TS-5764 - Grails in Depth
PDF
Grails Launchpad - From Ground Zero to Orbit
PPT
Fast web development using groovy on grails
ODP
Groovygrailsnetbeans 12517452668498-phpapp03
PDF
PDF
Grails 101
PDF
Groovy - Grails as a modern scripting language for Web applications
PDF
Grails 101
PPTX
Introduction to Grails 2013
PDF
Grails @ Java User Group Silicon Valley
PPT
Groovy & Grails: Scripting for Modern Web Applications
ODP
Groovy and Grails intro
PPT
Introduction To Groovy 2005
PDF
Grails beginners workshop
Grails Introduction - IJTC 2007
Agile web development Groovy Grails with Netbeans
Introduction to Grails Framework
Introduction To Grails
intoduction to Grails Framework
SVCC Intro to Grails
JavaOne 2008 - TS-5764 - Grails in Depth
Grails Launchpad - From Ground Zero to Orbit
Fast web development using groovy on grails
Groovygrailsnetbeans 12517452668498-phpapp03
Grails 101
Groovy - Grails as a modern scripting language for Web applications
Grails 101
Introduction to Grails 2013
Grails @ Java User Group Silicon Valley
Groovy & Grails: Scripting for Modern Web Applications
Groovy and Grails intro
Introduction To Groovy 2005
Grails beginners workshop

More from Sven Haiges (10)

PDF
NFC and Commerce combined
PDF
End to End Realtime Communication using Mobiel Devices and the Web
PDF
NFC Android Introduction
PDF
Gesture-controlled web-apps
KEY
CouchDB on Android
KEY
NFC on Android - Near Field Communication
PDF
Android UI
KEY
PPT
Grails and Dojo
ODP
Grails 0.3-SNAPSHOT Presentation WJAX 2006
NFC and Commerce combined
End to End Realtime Communication using Mobiel Devices and the Web
NFC Android Introduction
Gesture-controlled web-apps
CouchDB on Android
NFC on Android - Near Field Communication
Android UI
Grails and Dojo
Grails 0.3-SNAPSHOT Presentation WJAX 2006

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Cloud computing and distributed systems.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
cuic standard and advanced reporting.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Empathic Computing: Creating Shared Understanding
Big Data Technologies - Introduction.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Unlocking AI with Model Context Protocol (MCP)
Understanding_Digital_Forensics_Presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
Cloud computing and distributed systems.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25 Week I
cuic standard and advanced reporting.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks
Empathic Computing: Creating Shared Understanding

Grails 0.3-SNAPSHOT Presentation WJAX 2006 English

  • 1. GRAILS RAPID WEB APPLICATION DEVELOPMENT MADE EASY
  • 2. About: Sven Haiges Actionality Deutschland GmbH Senior Java Developer Diplom-Informatiker (FH), MBA My personal framework evolution: Struts, JSF, Spring MVC, GRAILS Since Juli 2006: Grails Podcast, Grails Screencasts
  • 3. Goals What is Grails & how do I create my first Grails app? What are the powerful cornerstones of Grails? Which features does Grails provide out of the box? Next Steps @ Home/Work
  • 4. Agenda Basics Foundations MVC Features Roadmap Your Next Steps
  • 6. Grails MVC Grails is an MVC Web Framework Inspired by Ruby on Rails Uses the powerful Groovy Scripting Language Convention Over Configuration Don't Repeat Yourself (DRY)
  • 7. Grails History & Team Started by Groovy enthusiasts: Guillaume LaForge, Steven Devijver and Graeme Rocher (current project lead) 0.1 was out March 29th, 2006 Current Team: Graeme Rocher, Marc Palmer, Dierk Koenig, Steven Devijer, Jason Rudolph, Sven Haiges... YOU!
  • 8. Using Grails Standalone Configuration details are hidden 0..100 in no time! Integrate with existing applications Still use the flexibility of Grails for existing DB-Schemas, HBM-Mappings, Spring Configuration, etc. Pimp your app!
  • 9. Powerful Foundations Foundations Groovy: 1 st class integration with Java Platform and all Java Code you have ever written! Spring: IoC, Spring MVC, WebFlow, ... Hibernate: powerful p ersistence Layer SiteMesh: flexible layout framework
  • 10. Installing Grails No previous Groovy installation needed, just a Java VM 1.4+ (but does not hurt :-) grails.org/Installation Download, extract, set GRAILS_HOME, add bin to PATH, run it! Type „grails“ to verify it works
  • 11. Your First Grails App „ grails create-app“ „ cd appName” „ grails run-app“ „ grails create-domain-class“, edit class „ grails generate-all“ „ grails run-app“
  • 13. Spring Spring Framework is used to hold everything together You can specify your own Spring Beans for injection into Controllers, Services, Jobs in spring/resources.xml Good to know: a Grails app is an Spring MVC app... Spring Webflow to be used in future
  • 14. Hibernate Hibernate is the de facto standard for O/R Mapping Grails maps your Domain Classes automatically, even creates and exports the schema to the database 1:n & m:n supported! Great flexibility: use your own HBM files for legacy database schemas!
  • 15. SiteMesh SiteMesh is a powerful Layout Framework and integrated into Grails grails-app/views/layout/main.gsp is the standard layout file This meta element in a head of a gsp file links it with the “main” layout: < meta name = &quot;layout&quot; content = &quot;main&quot; />
  • 16. Grails Philosophy Reuse (see foundations) No “reinventing the wheel” Coding by Convention without being locked into a single solution! Domain-Centric, not DB-Centric DRY
  • 18. Model Above is a Domain Class .groovy files living in grails-app/domain Persistent id, version, equals, hashCode, toString is generated automatically, but can be overridden class Book { String title }
  • 19. Model You will typically use this convenience target to create Domain Classes Will ask you for the name, make it uppercase if you forget > grails create-domain-class
  • 20. Model 1:1 mapping with Author Specify the “owning side” with this class Book { Author author String title } class Book { def belongsTo = Author Author author String title }
  • 21. Model 1:n mapping: Author has many Books Property “books” created automatically Same for adder method: class Author { def hasMany = [ books : Book ] String name } author.addBook(new Book(title:'Grails')) author.save()
  • 22. Model m:n possible, too! BelongsTo defines “owning side” class Book { def belongsTo = Author def hasMany = [authors:Author] } class Author { def hasMany = [books:Book] }
  • 23. Model Constraints defined via constraints closure Affects generation of views, too! class User { String login String password String email Date age static constraints = { login(length:5..15,blank:false,unique:true) password(length:5..15,blank:false) email(email:true,blank:false) age(min:new Date(),nullable:false) } }
  • 24. Model Dynamic Finder Methods def results = Book.findByTitle(&quot;The Stand&quot;) results = Book.findByTitleLike(&quot;Harry Pot%&quot;) results = Book.findByReleaseDateBetween( firstDate, secondDate ) results = Book.findByReleaseDateGreaterThan( someDate ) You can also use Query by Example (QBE) the Hibernate Criteria Builder, or direct HQL queries!
  • 25. Model Database configuration is done in grails-app/conf directory DevelopmentDataSource.groovy ProductionDataSource.groovy TestDataSource.groovy If you hit “grails run-app” the dev datasource is the default
  • 26. Model “grails war” creates your deployment war file with the production datasource class DevelopmentDataSource { boolean pooling = true // one of 'create', 'create-drop','update' //String dbCreate = &quot;create-drop&quot; String url = &quot;jdbc:postgresql://localhost:5432/act_dev&quot; String driverClassName = &quot;org.postgresql.Driver&quot; String username = &quot;dev&quot; String password = &quot;devpw&quot; def logSql = true //enable logging of SQL generated by Hibernate }
  • 27. Model BootStrap files are picked up at startup and can be used to create initial (test) data class CompanyBootStrap { def init = { servletContext -> //Delete all data in the tables that we work on Company.executeUpdate( &quot;delete Company&quot; ) //now create the test data Company c1 = new Company(name: 'bmw' ) c1.addUser( new User(name: 'herbert' , admin: true , ...)) .save() } ...
  • 28. View Groovy Server Pages(GSP) or JavaServer Pages (JSP) TagLibs for both, but GSP is groovin' All views are in the grails-app/views directory Generate views for your domain class: “grails generate-views”
  • 29. View Example GSP / uses “main” Layout < html > < head > < meta name = &quot;layout&quot; content = &quot;main&quot; /> < title > BlogEntry List </ title > </ head > < body > < div class = &quot;nav&quot; > < span class = &quot;menuButton&quot; > < g:link controller = &quot;authentication&quot; action = &quot;viewControllers&quot; > Home </ g:link ></ span > < span class = &quot;menuButton&quot; >< g:link action = &quot;create&quot; > New BlogEntry </ g:link ></ span > </ div > < div class = &quot;body&quot; > ... </ div > ...
  • 30. View Dynamic Tag Libraries Tags are fun again! “grails create-taglib” A plain *TagLib.groovy file in grails-app/taglib As with GSPs & Controllers: no server restart!
  • 31. View TagLib example (“simple” tag) class MyTagLib { includeJs = { attrs -> out << &quot;<script src='scripts/ ${attrs['script']} .js' />&quot; } } OutputStream is available via “out” All attributes are in the attrs map Usage of GStrings keeps tags readable
  • 32. View Logical and iterative tags just as easy. You can even call tags as “methods” within GSP – here used as normal tag: <g:hasErrors bean=&quot;${book}&quot; field=&quot;title&quot;> <span class='label error'>There were errors on the book title</span> </g:hasErrors> Or as method: <span id=&quot;title&quot; class=&quot;label ${hasErrors(bean:book,field:'title','errors')}&quot;>Title</span>
  • 33. View Creating markup from tags is a piece of cake: def dialog = { attrs, body -> mkp { div('class':'dialog') { body() } } } Above example uses a Groovy MarkupBuilder
  • 34. Controller All controllers are mapped to the Grails dispatcher servlet Create a new controller via: “grails create-controller” Or generate the controller based on an existing Domain Class: “grails generate-controller”
  • 35. Controller Default Mapping Convention http://.../appName/controller/action/id Some properties automatically available flash – map stores messages for next request log - a Log4J logger instance params – map with all request parameters request/response/servletContext etc.
  • 36. Controller Example generated controller: class AdvertisementController { def index = { redirect(action:list,params:params) } def list = { [ advertisementList: Advertisement.list( params ) ] } def show = { [ advertisement : Advertisement.get( params.id ) ] } ...
  • 37. Controller You can also use dynamic scaffolding: class BookController { def scaffold = Book } list/show/edit/delete/create/save/ update “dynamically” available You can still override actions “grails generate-all” creates all views and all controller actions for a domain class
  • 38. Controller Grails Services can be used to encapsulate business logic Services may be injected into Controllers “grails create-service” creates a new service in grails-app/services
  • 39. Controller Example Service class CountryService { def String sayHello(String name) { return &quot;hello ${name}&quot; } } Used within a controller class GreetingController { CountryService countryService def helloAction = { render(countryService.sayHello(params.name)) } }
  • 40. About Scaffolding... Use it to get up to speed, have something to show and work on You will not scaffold your complete web application Learn from the generated code, tweak it to fit your individual needs
  • 42. Auto Reloading In development mode, Grails synchronizes the current application with the server Controllers, GSPs, Tag Libraries, Domain Classes, Services, etc. This is essential for an iterative and incremental development. Call it “agile” if you like!
  • 43. Spring Integration You can put additional Spring configuration in the /spring directory and use it to configure your beans Automatic DI is available even for these beans (not just Services) Easily integrate existing (Java) functionality that was configured with Spring
  • 44. Hibernate Integration You can specify your own HBM files for your domain classes. (You can even use your existing Java classes if you like) Working with legacy database schemas is getting really simple Still use all benefits like dynamic finder methods
  • 45. Eclipse “Integration” Grails creates an Eclipse Project file automatically, just run File > Import > Existing Project You'll have to tweak some file names if you use the development snapshot versions Be sure to install the Groovy Plugin: groovy.codehaus.org/Eclipse+Plugin
  • 46. AJAX Grails supports AJAX with different AJAX toolkits, currently Prototype, Dojo and Yahoo Special AJAX tags can be used for asynchronous calls and form submission <div id=&quot;message&quot;></div> <g:remoteLink action=&quot;delete&quot; id=&quot;1&quot; update=&quot;message&quot;>Delete Book</g:remoteLink>
  • 47. AJAX On the server side, Grails supports AJAX via the render() Method, which makes AJAX responses really easy: def time = { render(contentType:'text/xml') { time(new Date()) } } Render() supports MarkupBuilders for XML, HTML, JSON, OpenRico
  • 48. Job Scheduling Grails makes using Quartz even easier, just create this (in grails-app/jobs): class MyJob { def cronExpression = &quot;0,15,30,45 * * * * ?&quot; //every 15 seconds def execute(){ println &quot;Running job!&quot; } }
  • 49. Unit & Functional Testing Both unit and functional testing supported Functional Testing uses Canoo Webtest “grails test-app” runs the unit tests “grails run-webtest” Generate a webtest with “grails generate-webtest”
  • 51. The Sandbox New Controllers Page Flows Constraints for DB-Schema creation Laszlo on Grails Mail / Messaging Integration Test DataSets Plugin-System
  • 52. Roadmap 0.3 Spring 2 Web Services Service Classes M:N Mapping for GORM 0.4 DWR Support for Service Classes Pluggable Persistence Layer
  • 53. Roadmap 0.5 XML-RPC for Service Classes Generation of Domain Model from DB Schema 0.6 Scaffolding of User Authentication Code Grails is user-centric, you define what really happens. Vote in Jira: http://jira.codehaus.org/browse/GRAILS
  • 55. Learn more Download, Install, create your first app with the Quickstart Guide http://www.grails.org/Quick+Start Check out the Tutorials Section http://www.grails.org/Tutorials
  • 56. Learn more Read & Work through the user guide http://www.grails.org/User+Guide Get onto the Grails user mailing list http://www.grails.org/Mailing+lists Remember: Grails is open source... The more you contribute, the more you get out in terms of learning, jobs, contacts...
  • 57. Watch Currently two screencasts available Scaffolding Directory Structure http://www.grails.org/Grails+Screencasts
  • 58. Listen Grails Podcast Weekly Show Grails News Grails Features Interviews Agile Development http://hansamann.podspot.de/rss
  • 59. Read Out soon! By Graeme Rocher, Grails Project Lead ISBN: 1-59059-758-3
  • 60. Contribute Be part of the community Contribute a Tag! grails.org/Contribute+a+Tag Blog about Grails! Now! Answer questions on the Grails Users List! and...
  • 61. Groovy & Grails Shop Buy your girlfriend one of those sexy Groovy GStrings http://tinyurl.com/y3zmos New!
  • 62. GRAILS RAPID WEB APP DEVELOPMENT MADE EASY Questions? www.grails.org www.svenhaiges.de