Grails presentations
Upcoming SlideShare
Loading in...5
×
 

Grails presentations

on

  • 915 views

 

Statistics

Views

Total Views
915
Views on SlideShare
913
Embed Views
2

Actions

Likes
0
Downloads
21
Comments
0

1 Embed 2

http://www.slideshare.net 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Grails presentations Grails presentations Presentation Transcript

    • Rapid Web Application Development with Grails Graeme Rocher Managing Director Agilize it http://www.agilizeit.com Session ID# BOF-2521
    • Goal of this Talk
        • Learn how to rapidly create web applications using the agile web application framework Grails
      Rapid Web Application Development with Grails
    • Agenda
      • Groovy & Grails
      • Getting Started
      • The Application Domain
      • Controllers
      • Groovy Servers Pages (GSP)
      • Tag Libraries
      • Ajax Support
      • Scaffolding
      • Java Integration
    • Agenda
      • Groovy & Grails
      • Getting Started
      • The Application Domain
      • Controllers
      • Groovy Servers Pages (GSP)
      • Tag Libraries
      • Ajax Support
      • Scaffolding
      • Java Integration
    • Groovy & Grails
      • Grails: MVC web framework inspired by:
          • Convention over Configuration
          • Don’t Repeat Yourself (DRY)
          • Ruby on Rails
      • Built on solid foundations:
          • Spring IoC, MVC and WebFlow
          • Hibernate
          • SiteMesh
      • Why Groovy?
          • Meta-Programming
          • Closure Support
          • Syntactically Expressive
          • Java Integration
      Source: Please add the source of your data here
    • Agenda
      • Groovy & Grails
      • Getting Started
      • The Application Domain
      • Controllers
      • Groovy Servers Pages (GSP)
      • Tag Libraries
      • Ajax Support
      • Scaffolding
      • Java Integration
    • Getting Started
      • Grails available from http://grails.org
      • Stable & Development snapshots available
      • Simple installation:
        • Download & extract zip
        • Set GRAILS_HOME variable
        • Add $GRAILS_HOMEin to PATH variable
      • Run “grails create-app ”
      Source: Please add the source of your data here
    • Project Infrastructure
            • + PROJECT_HOME
            • + grails-app
            • + conf
            • + controllers
            • + domain
            • + i18n
            • + services
            • + taglib
            • + views
            • + lib
            • + spring
            • + hibernate
            • + src
            • + web-app
      Main Grails resources Additional Spring configuration Additional Hibernate mapping Web resources e.g. CSS, JavaScript etc. Java sources Jar archive libraries
    • Command Line Targets
      • Apache Ant bundled with Grails
      • Many useful targets available:
        • create-* (for creating Grails artifacts)
        • generate-controller
        • generate-views
        • run-app
        • test-app
        • run-webtest
      Source: Please add the source of your data here
    • The Data Source // data source located in grails-app/conf Class ApplicationDataSource { @Property pooled = false @Property dbCreate = “ create-drop ” @Property url = “jdbc:hsqldb:mem:testDb” @Property driverClassName = “org.hsqldb.jdbcDriver” @Property username = “sa” @Property password = “sa” } Whether connection Pooling is enabled DB Auto creation with hbm2ddl Remaining connection settings
    • Agenda
      • Groovy & Grails
      • Getting Started
      • The Application Domain
      • Controllers
      • Groovy Servers Pages (GSP)
      • Tag Libraries
      • Ajax Support
      • Scaffolding
      • Java Integration
    • The Application Domain
      • Domain classes hold state and implement behaviour
      • They are linked together via relationships (e.g. one-to-many)
      • In Java domain classes have traditionally been handled by Object-Relational Mapping (ORM)
      • Grails provides simple ORM built on Hibernate
      Source: Please add the source of your data here
    • Grails ORM (GORM)
      • Extremely simple. No special class to extend or file to configure!
      • class ExpenseReport {
      • @Property Long id
      • @Property Long version
      • @Property relatesToMany = [ items :ExpenseItem]
      • @Property Set items
      • @Property Date submissionDate
      • @Property String employeeName
      • }
      Each domain class has an ‘id’ and ‘version’ Defines one-to-many relationship to ExpenseItem
    • Grails ORM (GORM)
      • We’ve got this far, so lets define the other side!
      • class ExpenseItem {
      • @Property Long id
      • @Property Long version
      • @Property belongsTo = ExpenseReport
      • @Property String type
      • @Property Currency currency
      • @Property Integer amount
      • }
      Defines the owning side of the relationship Each property maps To a column
    • Grails Constraints
      • Validation constraints can be defined using the ‘constraints’ property
            • class ExpenseItem {
            • @Property constraints = { type (inList:[ ' travel ' , ' accomodation ' ])
            • amount (range:1..999)
            • }
            • }
      Each node relates to a property Ensures the ‘type’ property Is one of the values in the list ‘ amount’ must be in a range greater than 0 but less than 1000
    • Dynamic Methods & Properties
      • Grails injects methods and properties into domain classes at runtime:
      • def r = ExpenseReport. findBy EmployeeName ( ' fred ' )
      • def r = ExpenseReport
      • . findBy SubmissionDate GreaterThan (lastMonth)
      • def reports = ExpenseReport. findAll ()
      • assert ! (new ExpenseItem(). validate ())
      • def er = new ExpenseReport(employeeName: ' Edgar ' )
      • . save ()
    • Agenda
      • Groovy & Grails
      • Getting Started
      • The Application Domain
      • Controllers
      • Groovy Servers Pages (GSP)
      • Tag Libraries
      • Ajax Support
      • Scaffolding
      • Java Integration
    • Controllers
      • Controllers handle requests and prepare responses
      • Response created by either delegating to a view or writing to the response
      • A controller is a class containing closure properties that act on requests
      • The convention used for the name of the controller and the actions within map to URIs.
      Source: Please add the source of your data here
    • The Controller
      • The controller and action name map to the URI: /expenseReport/list
      • class ExpenseReport Controller {
      • @Property list = {
      • [ expenseReports : ExpenseReport.list()]
      • }
      • }
      The name of the class is the first token in the URI Each action is a closure property An optional model is returned as a map
    • Data Binding & Flow Control
      • // save action
      • @Property save = {
      • def e = ExpenseItem.get(params.id)
      • e.properties = params
      • if(e. save ()){ redirect(action:show,id:e.id)
      • } else {
      • render( view: ' create ' ,
      • model:[expenseItem:e] )
      • }
      • }
      Auto-type conversion from request parameters Dynamic get method Auto-type conversion To id type Example flow control via render and redirect methods
    • Agenda
      • Groovy & Grails
      • Getting Started
      • The Application Domain
      • Controllers
      • Groovy Servers Pages (GSP)
      • Tag Libraries
      • Ajax Support
      • Scaffolding
      • Java Integration
    • Groovy Server Pages
      • A view technology very similar to JSP, but with Groovy as the primary language
      • More expressive and concise with support for embedded GStrings & Tags
      • Layout support through integration with SiteMesh
      • Ability to define dynamic tag libraries
      Source: Please add the source of your data here
    • A GSP Example
      • The GSP for the list action is named according to convention: grails-app/views/expenseItem/list.gsp
      • <html>
      • <body>
      • <g:each in= &quot; ${ expenseItems } &quot; >
      • <p> ${it.type} – amount: ${it.amount} </p>
      • </g:each>
      • </body>
      • </html>
      References the model returned by the controller Embedded GString expressions
    • Agenda
      • Groovy & Grails
      • Getting Started
      • The Application Domain
      • Controllers
      • Groovy Servers Pages
      • Tag Libraries
      • Ajax Support
      • Scaffolding
      • Java Integration
    • Dynamic Tag Libraries
      • Easy definition of simple, logical and iterative tags:
      • class Expense TagLib {
      • @Property dateFormat = { attrs,body ->
      • out << new SimpleDateFormat( attrs .format)
      • .format( attrs .date)
      • }
      • }
      The name of the tag The body argument is a closure that can be invoked The attributes are passed as a map
    • Dynamic Tag Libraries
      • Using the tag requires no imports or configuration and can be reloaded at runtime!:
      • <p>Submitted:
      • <g: dateFormat date = &quot; ${report.submissionDate} &quot;
      • format = &quot; DD-MM-YYYY &quot; />
      • </p>
      • <p><input type= &quot; hidden &quot; name= &quot; submissionDate &quot;
      • value= &quot; ${ dateFormat (
      • date :report.submissionDate,
      • format : ' DD-MM-YYYY ' )} &quot; />
      • </p>
      Tag called by name with the “g:” prefix Tag can also be called as a regular method!
    • Agenda
      • Groovy & Grails
      • Getting Started
      • The Application Domain
      • Controllers
      • Groovy Servers Pages
      • Tag Libraries
      • Ajax Support
      • Scaffolding
      • Java Integration
    • AJAX Support
      • Built in “ adaptive ” tag library for Ajax
      • Supports Prototype, Rico, and Yahoo (Dojo coming soon)
      • Tags for remote linking, asynchronous form submission etc.
      • Dynamic “ render ” method available for rendering XML snippets, or partial templates
      • Save/Reload and dynamic tag libraries make Ajax even easier
    • Agenda
      • Groovy & Grails
      • Getting Started
      • The Application Domain
      • Controllers
      • Groovy Servers Pages
      • Tag Libraries
      • Scaffolding
      • Ajax Support
      • Java Integration
    • DEMO
      • Scaffolding
    • Agenda
      • Groovy & Grails
      • Getting Started
      • The Application Domain
      • Controllers
      • Groovy Servers Pages
      • Tag Libraries
      • Scaffolding
      • Ajax Support
      • Java Integration
    • Java Integration
      • Now for the important bit, with Groovy and Grails you can:
      • Call any existing Java library seamlessly
      • Deploy as a WAR onto any JEE application server
      • Write your domain model in Java , mapped with Hibernate, and still use dynamic methods!
      • Take advantage of Hibernate’s power by mapping onto legacy systems.
      • Use Spring’s dependency injection to integrate Controllers with existing services
    • DEMO
      • ECLIPSE INTEGRATION
    • Summary
      • With the advent on Web 2.0 agility is key
      • Dynamic frameworks (Grails, Rails, Django etc.) provide this through quick iterative development with a clear productivity gain
      • However, for large scale applications static-typing and IDE support is crucial
      • Grails provides the ability to use a blended approach
      • And most importantly it runs on the JVM !
    • For More Information
        • Groovy website – http://groovy.codehaus.org
        • Grails website – http://grails.org
        • Mailing lists – http:// grails.org/Mailing+lists
        • Graeme’s Blog – http://graemerocher.blogspot.com
        • Upcoming books ‘The Definitive Guide to Grails’ by Apress and ‘Groovy in Action’ by Manning
    • Q&A