SlideShare a Scribd company logo
1 of 58
Groovy & Grails Lightning Talk Raphael Volz Sep. 10, 2007 FZI, Karlsruhe ,[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object]
Why should I care ? 40-60% User Interface 40-60% Functionality Software Development Effort Variance Max. 20 % User Interface Min. 80% Functionality Focus : Users    Great Interface  Developer    Gigantic Functionality Typically Research … try to be efficient in programming efforts … ... try to be efficient in UI efforts...
Efficiency Problems in Web Development ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java’s biggest strengths in Web development ? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Problems with Java in Web Dev’t ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object]
Get Groovy – An agile dynamic language for Java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // Simplifying Java Syntax (1) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Declare all imports Imports PUBLIC PRIVATE Default scope OPTIONAL MUST Typing of variables OPTIONAL MUST Brackets with method calls OPTIONAL MUST Semicolon after statement Groovy Java Feature
Groovy // New features beyond Java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // Hello World ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Println “Hello World” class HelloWorld { static void  main (String[] args) {   System.out.println(   “Hello World”); } } class HelloWorld { static main (args) {   System.out.println(   “Hello World”); } } class HelloWorld { static main (args) { println(“Hello World”); } } println(“Hello World”); Println “Hello World”
Groovy // Closures : Blocks of code as objects ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Remember LISP ? ... pass around as references, store, execute at arbitratry time ... similar to anonymous inner classes, but nicer syntax and more flexible
Groovy // Calling Java APIS ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Closure
Groovy // Everything is an object ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Very, very useful when writing test code !!!
Groovy // Groovy Beans vs. Java Beans ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // Simplified List Handling ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // List Handling Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Select all names with at most  3 characters from a list Groovy Java list = [&quot;Rod&quot;, &quot;James&quot;, &quot;Chris&quot;] shorts = list.findAll { it.size() <= 4 } shorts.each { println it }
Groovy // Ranges and Maps ,[object Object],[object Object],[object Object],[object Object]
Basic Sorting ,[object Object],[object Object],[object Object],[object Object],[object Object]
Sorting JavaBeans ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // Operator Overloading ,[object Object],[object Object],[object Object]
Groovy // Advanced switch ,[object Object]
Groovy // Additional Library ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // Strings and Regular Expressions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // GPath path expressions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // Builders ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // XML Builder ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // XML Parser ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // Dynamic Features ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy // Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Typically 50% less  development effort  (*) Note: (*) Comes at higher debugging expense and 20-90% performance
Agenda ,[object Object],[object Object],[object Object]
What is GRAILS ? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
GRAILS // Layering on Java Components Source: G. K. Rocher, The Definite Guide to Grails, Apress, 2006, p. 7
GRAILS // Step 1
Source: G. K. Rocher, The Definite Guide to Grails, Apress, 2006, p. 39
GRAILS // Basic application already there after Step 1
GRAILS // Step 2 - Define a Model ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
GRAILS // GRAILS Contribution ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
GRAILS // Step 3 Generation of views and controllers •  Once the Book class is created, let´s benefint  from static scaffolding ->  grails generate-all ->  grails run-app •  A BookController is created, as well as  four GSP:  ▪  create.gsp  ▪  edit.gsp  ▪  list.gsp   ▪  show.gsp
GRAILS // Scaffolding provides basic GUI for CRUD
GRAILS // Taking control of GRAILS V iew M odel C ontroller grails generate-controller /grails-app/controllers grails generate-views /grails-app/views grails create-domain-class /grails-app/model J obs S ervices /grails-app/jobs /grails-app/services grails create-app 1 2 Web Test Unit Test 4 5 6 grails generate-all 3
GRAILS // VIEW CONTROLLER INTERACTION Source: G. K. Rocher, The Definite Guide to Grails, Apress, 2006
GRAILS // Hibernate interaction •  Hibernate is the de facto ORM solution •  Domain classes are automatically and  transparently mapped  with Hibernate •  1:1, 1:n & m:n realtionships supported •  Various database environments (dev, test, prod) •  Default HSQLDB in-memory config •  You can even provide  your own Hibernate  mapping files for legacy schemas •  You can also  reuse your EJB3 ! V M C S J
GRAILS // A more complex domain class  Author  { String  firstName String  lastName def  hasMany = [books:  Book ] String  toString()   { “ $firstName $lastName” } } class  Book  { String  title Author  author Publisher  publisher def  belongsTo =  [ Publisher , Author ] String  toString() { title } } class  Publisher  {   String  name def  hasMany = [   books:  Book ] String  toString() { name } } Author  has many  Books Publisher  has many  Books V M C S J
GRAILS // Domain with constraints to keep valid Add an email to Author class  Author  { String email // … static  constraints =  { email (email: true) } } Add an ISBN to Book class  Book  { Stringisbn // … static  constraints = { isbn (matches: “  [0-9]  {9} [0-9X ]”) } } V M C S J
GRAILS // ... and even more constraints •  Many constraints available: blank , creditcard, email,  inList , length, min,  minLength, minSize,  matches , max, maxLength,  maxSize, notEqual,  nullable ,  range , size,  unique ,  url , validator •  And you can create your own closure validator: even( validator:  { it % 2 == 0  )} V M C S J
GRAILS // Querying your Model ,[object Object],[object Object],[object Object],[object Object],[object Object],V M C S J
GRAILS // Query Examples •  Book. find By Title  (“The Stand”) Book.findByTitle Like (“Harry Pot%”) Book.findByReleaseData Between (start, end) Book.findByTitleLike Or ReleaseData LessThan ( “ %Grails%”, someData) •  Find by relationship Book.find All By Author ( Author.get(1) ) •  Affect sorting Book.findAllbyAuthor(me, [sort:‘title’,order:’asc’] ) V M C S J
GRAILS // Views •  Spring MVC  under the hood •  Support for flash scope between requests •  GSP : Groovy alternative to JSP •  Dynamic taglib  development: no TLD, no configuration, just conventions •  Adaptive AJAX tags  (Yahoo, Dojo, Prototype) •  Customizable  layout with SiteMesh •  Page fragments through reusable templates •  View under grails-app/views V M C S J TIP:  Use  grails install-templates  to install and  customize your the templates to be used  for generation (templates in ../src/templates)
GRAILS // GSP Groovy Server Pages <html> <head>   <meta name=“layout“ content=“main“ />   <title>Book List</title> </head> <body>   <a href=“ $ {createLinkTo(dir:’’)} ”>Home</a>   <g:link action=“create”> New Book</g:link>   <g:if test=“ $ { flash.message } ”>   ${flash.message}   </g:if>   <g:each in=“${bookList}”> $ {it.title} </g:each> </body> </html> V M C S J
GRAILS // Rich Set of Dynamic Tag Libs •  Logical:  if, else, elseif •  Iterative:  while, each, collect, findAll… •  Linking:  link, createLink, createLinkTo •  Ajax:  remoteFunction, remoteLink, formRemote,  submitToRemote… •  Form:  form, select, currencySelect, localSelect,  datePicker, checkBox… •  Rendering:  render*, layout*, paginate… •  Validation:  eachError, hasError, message •  UI:  rich TextEditor… V M C S J
GRAILS // URL Convention •  URL mapping convention: controller/action/id http://localhost:8080/library/ book / show / 1 •  Scaffolding can be ▪   dynamic (def scaffold = true) ▪  static (code generation) •  Controllers pass data to the view through maps •  Direct access to parameters •  Easy redirect and forward •  Can define allowed methods for each action V M C S J
GRAILS // Controllers provide actions to execute (call) class  Book Controller  { def index = {  redirect(action:list,params:params)  } def list = {  [ bookList: Book.list( params )]  } def  show  = { [ book : Book.get(  params.id  ) ]  } def edit = {  def book = Book.get( params.id ) if(!book) { flash.message  = “Book ${params.id} not found” redirect(action:list)  }  else return  [ book : book ] } } V M C S J
GRAILS // Chaining and Flashing Source: G. K. Rocher, The Definite Guide to Grails, Apress, 2006
GRAILS // Services •  Services are Groovy classes that should contain your  business logic •  Automatic injection of services  in controllers & services simply by declaring a field: class  BookController  { MySuperService mySuperService } V M C S J
Grails // Jobs •  You can create recuring events with Quartz  under the hood, configured by Spring •  Again a convention on the name and directory •  Regular intervals, or cron definitions •  class My Job   {} def cronExpression =  “0 0 24 * * ?” def execute()  {   print “Job run!” } } V M C S J
Further Reading
Concluding Notes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

What's hot (20)

Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentation
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Functional Programming & Event Sourcing - a pair made in heaven
Functional Programming & Event Sourcing - a pair made in heavenFunctional Programming & Event Sourcing - a pair made in heaven
Functional Programming & Event Sourcing - a pair made in heaven
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming language
 
iSoligorsk #3 2013
iSoligorsk #3 2013iSoligorsk #3 2013
iSoligorsk #3 2013
 
Down the Rabbit Hole
Down the Rabbit HoleDown the Rabbit Hole
Down the Rabbit Hole
 
Know yourengines velocity2011
Know yourengines velocity2011Know yourengines velocity2011
Know yourengines velocity2011
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
 

Viewers also liked

Continental Drift Theory
Continental Drift TheoryContinental Drift Theory
Continental Drift Theory
jjconnolly
 

Viewers also liked (9)

Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
 
Nested and Parent/Child Docs in ElasticSearch
Nested and Parent/Child Docs in ElasticSearchNested and Parent/Child Docs in ElasticSearch
Nested and Parent/Child Docs in ElasticSearch
 
Continental Drift Theory
Continental Drift TheoryContinental Drift Theory
Continental Drift Theory
 
Enterprise 2.0 Portale mit Grails. Geht das?
Enterprise 2.0 Portale mit Grails. Geht das?Enterprise 2.0 Portale mit Grails. Geht das?
Enterprise 2.0 Portale mit Grails. Geht das?
 
Grails im Überblick und in der Praxis
Grails im Überblick und in der PraxisGrails im Überblick und in der Praxis
Grails im Überblick und in der Praxis
 
Kann ich mit Grails Enterprise Applikationen umsetzen?
Kann ich mit Grails Enterprise Applikationen umsetzen?Kann ich mit Grails Enterprise Applikationen umsetzen?
Kann ich mit Grails Enterprise Applikationen umsetzen?
 
Open Source Creativity
Open Source CreativityOpen Source Creativity
Open Source Creativity
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...
 

Similar to 2007 09 10 Fzi Training Groovy Grails V Ws

Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
James Williams
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovy
manishkp84
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
Andres Almiray
 
Java Intro
Java IntroJava Intro
Java Intro
backdoor
 

Similar to 2007 09 10 Fzi Training Groovy Grails V Ws (20)

Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
 
Eclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To GroovyEclipsecon08 Introduction To Groovy
Eclipsecon08 Introduction To Groovy
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovy
 
Groovy!
Groovy!Groovy!
Groovy!
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 
Groovy
GroovyGroovy
Groovy
 
Groovy
GroovyGroovy
Groovy
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Groovy a Scripting Language for Java
Groovy a Scripting Language for JavaGroovy a Scripting Language for Java
Groovy a Scripting Language for Java
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
 
Java Intro
Java IntroJava Intro
Java Intro
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
Programming Under Linux In Python
Programming Under Linux In PythonProgramming Under Linux In Python
Programming Under Linux In Python
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Introduction to Oracle Groovy
Introduction to Oracle GroovyIntroduction to Oracle Groovy
Introduction to Oracle Groovy
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 

More from loffenauer (6)

Mobile Reiseführer für Ihre Destination(en) - Vorteile und Möglichkeiten Mobi...
Mobile Reiseführer für Ihre Destination(en) - Vorteile und Möglichkeiten Mobi...Mobile Reiseführer für Ihre Destination(en) - Vorteile und Möglichkeiten Mobi...
Mobile Reiseführer für Ihre Destination(en) - Vorteile und Möglichkeiten Mobi...
 
nogago distributed bulk rendering
nogago distributed bulk renderingnogago distributed bulk rendering
nogago distributed bulk rendering
 
Office 2.0
Office 2.0Office 2.0
Office 2.0
 
innoraise - know who knows
innoraise - know who knowsinnoraise - know who knows
innoraise - know who knows
 
Aktuelle Trends und Technologien für Soziale Netzwerke in Unternehmen
Aktuelle Trends und Technologien für Soziale Netzwerke in UnternehmenAktuelle Trends und Technologien für Soziale Netzwerke in Unternehmen
Aktuelle Trends und Technologien für Soziale Netzwerke in Unternehmen
 
Change Paths In Reasoning !
Change Paths In Reasoning !Change Paths In Reasoning !
Change Paths In Reasoning !
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

2007 09 10 Fzi Training Groovy Grails V Ws

  • 1.
  • 2.
  • 3. Why should I care ? 40-60% User Interface 40-60% Functionality Software Development Effort Variance Max. 20 % User Interface Min. 80% Functionality Focus : Users  Great Interface  Developer  Gigantic Functionality Typically Research … try to be efficient in programming efforts … ... try to be efficient in UI efforts...
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33. GRAILS // Layering on Java Components Source: G. K. Rocher, The Definite Guide to Grails, Apress, 2006, p. 7
  • 35. Source: G. K. Rocher, The Definite Guide to Grails, Apress, 2006, p. 39
  • 36. GRAILS // Basic application already there after Step 1
  • 37.
  • 38.
  • 39. GRAILS // Step 3 Generation of views and controllers • Once the Book class is created, let´s benefint from static scaffolding -> grails generate-all -> grails run-app • A BookController is created, as well as four GSP: ▪ create.gsp ▪ edit.gsp ▪ list.gsp ▪ show.gsp
  • 40. GRAILS // Scaffolding provides basic GUI for CRUD
  • 41. GRAILS // Taking control of GRAILS V iew M odel C ontroller grails generate-controller /grails-app/controllers grails generate-views /grails-app/views grails create-domain-class /grails-app/model J obs S ervices /grails-app/jobs /grails-app/services grails create-app 1 2 Web Test Unit Test 4 5 6 grails generate-all 3
  • 42. GRAILS // VIEW CONTROLLER INTERACTION Source: G. K. Rocher, The Definite Guide to Grails, Apress, 2006
  • 43. GRAILS // Hibernate interaction • Hibernate is the de facto ORM solution • Domain classes are automatically and transparently mapped with Hibernate • 1:1, 1:n & m:n realtionships supported • Various database environments (dev, test, prod) • Default HSQLDB in-memory config • You can even provide your own Hibernate mapping files for legacy schemas • You can also reuse your EJB3 ! V M C S J
  • 44. GRAILS // A more complex domain class Author { String firstName String lastName def hasMany = [books: Book ] String toString() { “ $firstName $lastName” } } class Book { String title Author author Publisher publisher def belongsTo = [ Publisher , Author ] String toString() { title } } class Publisher { String name def hasMany = [ books: Book ] String toString() { name } } Author has many Books Publisher has many Books V M C S J
  • 45. GRAILS // Domain with constraints to keep valid Add an email to Author class Author { String email // … static constraints = { email (email: true) } } Add an ISBN to Book class Book { Stringisbn // … static constraints = { isbn (matches: “ [0-9] {9} [0-9X ]”) } } V M C S J
  • 46. GRAILS // ... and even more constraints • Many constraints available: blank , creditcard, email, inList , length, min, minLength, minSize, matches , max, maxLength, maxSize, notEqual, nullable , range , size, unique , url , validator • And you can create your own closure validator: even( validator: { it % 2 == 0 )} V M C S J
  • 47.
  • 48. GRAILS // Query Examples • Book. find By Title (“The Stand”) Book.findByTitle Like (“Harry Pot%”) Book.findByReleaseData Between (start, end) Book.findByTitleLike Or ReleaseData LessThan ( “ %Grails%”, someData) • Find by relationship Book.find All By Author ( Author.get(1) ) • Affect sorting Book.findAllbyAuthor(me, [sort:‘title’,order:’asc’] ) V M C S J
  • 49. GRAILS // Views • Spring MVC under the hood • Support for flash scope between requests • GSP : Groovy alternative to JSP • Dynamic taglib development: no TLD, no configuration, just conventions • Adaptive AJAX tags (Yahoo, Dojo, Prototype) • Customizable layout with SiteMesh • Page fragments through reusable templates • View under grails-app/views V M C S J TIP: Use grails install-templates to install and customize your the templates to be used for generation (templates in ../src/templates)
  • 50. GRAILS // GSP Groovy Server Pages <html> <head> <meta name=“layout“ content=“main“ /> <title>Book List</title> </head> <body> <a href=“ $ {createLinkTo(dir:’’)} ”>Home</a> <g:link action=“create”> New Book</g:link> <g:if test=“ $ { flash.message } ”> ${flash.message} </g:if> <g:each in=“${bookList}”> $ {it.title} </g:each> </body> </html> V M C S J
  • 51. GRAILS // Rich Set of Dynamic Tag Libs • Logical: if, else, elseif • Iterative: while, each, collect, findAll… • Linking: link, createLink, createLinkTo • Ajax: remoteFunction, remoteLink, formRemote, submitToRemote… • Form: form, select, currencySelect, localSelect, datePicker, checkBox… • Rendering: render*, layout*, paginate… • Validation: eachError, hasError, message • UI: rich TextEditor… V M C S J
  • 52. GRAILS // URL Convention • URL mapping convention: controller/action/id http://localhost:8080/library/ book / show / 1 • Scaffolding can be ▪ dynamic (def scaffold = true) ▪ static (code generation) • Controllers pass data to the view through maps • Direct access to parameters • Easy redirect and forward • Can define allowed methods for each action V M C S J
  • 53. GRAILS // Controllers provide actions to execute (call) class Book Controller { def index = { redirect(action:list,params:params) } def list = { [ bookList: Book.list( params )] } def show = { [ book : Book.get( params.id ) ] } def edit = { def book = Book.get( params.id ) if(!book) { flash.message = “Book ${params.id} not found” redirect(action:list) } else return [ book : book ] } } V M C S J
  • 54. GRAILS // Chaining and Flashing Source: G. K. Rocher, The Definite Guide to Grails, Apress, 2006
  • 55. GRAILS // Services • Services are Groovy classes that should contain your business logic • Automatic injection of services in controllers & services simply by declaring a field: class BookController { MySuperService mySuperService } V M C S J
  • 56. Grails // Jobs • You can create recuring events with Quartz under the hood, configured by Spring • Again a convention on the name and directory • Regular intervals, or cron definitions • class My Job {} def cronExpression = “0 0 24 * * ?” def execute() { print “Job run!” } } V M C S J
  • 58.