Grails Introduction - IJTC 2007

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

  • + wulezhen Wu Lezhen 11 months ago
    I find it extremely useful. I hope I obtain the permission to download it.
Post a comment
Embed Video
Edit your comment Cancel

2 Favorites

Grails Introduction - IJTC 2007 - Presentation Transcript

  1. Grails Web app development with pleasure! Guillaume Laforge Vice-President, Technology G2One, Inc. http://www.g2one.com
  2. Goal of This Talk Discovering the Grails web framework
      • Learn more about Grails, how easily you can use it in your projects, and how to get back the pleasure of web development!
  3. Guillaume Laforge
    • Groovy Project Manager
    • JSR-241 Spec Lead
    • Initiator of the Grails framework
    • Co-author of Groovy in Action
      • By Dierk König, et al.
    • Vice-President Technology
  4. Agenda
    • What’s Grails?
    • The Problem with the usual web frameworks
    • The different layers
    • Other cool features
    • The plugin system
    • Summary
    • Q&A
  5. What’s Grails?
    • From 10,000 feet
    • From 1,000 feet
    • Near the ground
  6. What’s Grails? (1/3)
    • From 10,000 feet
    • Grails is an MVC action-based framework
    • Principles
      • CoC : Convention over Configuration
      • DRY : Don’t Repeat Yourself
    • The essence of Ruby on Rails, but with the tight integration with the Java ecosystem
      • Protect your investment!
  7. What’s Grails? (2/3)
    • From 1,000 feet
    = + +
  8. What’s Grails? (3/3)
    • Near the ground…
    • Grails is built on proven & solid OSS bricks
      • Spring : IoC, DI, Spring MVC, transactions…
      • Hibernate : ORM, querying mechanism
      • Groovy : for everything that matters
      • SiteMesh : page layout and composition
      • Quartz : for job scheduling
      • AJAX : integration with different libraries
      • Jetty & HSQLDB : for fast development cycles
  9. The Grails Stack
  10. Why Groovy?
    • Java-like syntax
      • Flat learning curve
    • The same programming models
      • Same OO, security, threading models
    • The same libraries
      • JDK, and any in-house or OSS JAR
    • And Groovy has…
      • Closures, properties, malleable syntax for DSLs
  11. The Problem
    • What’s the problem with Web frameworks?
    • Why has it got to be complex?
    • What are the pain points?
  12. Has it got to be complex?
      • But it’s slow to start with
        • Seting up the project takes time
      • It gets complicated pretty rapidly
        • Dive into Spring & Hibernate to wire everything together
      • There are so many layers
        • DAOs, DTOs, more abstraction layers
      • Too many configuration files
        • Often too much XML for everything
    • Struts / Spring / Hibernate is okay…
  13. The Pain Points
    • ORM persistence overly hard to master and get right
    • Numerous layers and configuration files lead to chaos
    • Ugly JSPs with scriptlets and the complexity of JSP tags
    • Grails addresses the fundamental flaws in Java web application development today without compromising the platform
  14. The Different Layers
    • Bottom-up!
      • Transparent persistence
      • Controllers and services
      • Groovy Server Pages, templates & taglibs
  15. Grails’ MVC at a Glance…
    • Model
      • GORM: Grails Object Relational Mapping
    • Controller
      • Multi-action controller
      • Also the Service layer & Quartz job scheduling
    • View
      • GSP: Groovy Server Pages
      • Tag libraries
  16. Pain Point #1 – Peristence
    • ORM is quite hard to master and get right
    • Many configuration files
    ibatis.xml hibernate.cfg.xml persistence.xml ejb-cmp.xml
  17. GORM – Grails Object Relational Mapping
    • Hibernate under the hood
    • Domain model is a set of POGOs
      • Plain Old Groovy Objects
      • POGOs are transparently mapped!
    • No hibernate.cfg.xml
      • But can be overriden if needed
    • All domain classes get useful instance and static methods for free
      • Book.count(), Book.list(), Book.get(id)…
      • book.save(), book.delete(), book.update()…
  18. Example
    • Grails provides a default ORM mapping strategy for Hibernate
    // A Book domain class class Book { String title Date releaseDate static belongsTo = [author: Author] } // A one-to-many class User { String name static hasMany = [bookmarks: Bookmark] } 18 8 Dec 2007 Groovy Recipes 17 2 11 Dec 2006 Groovy in Action 16 author_id release_date title id Dierk König 2 name id
  19. <DEMO/>
  20. Constraints
    • Constraints are added in domain classes through a static constraint field:
      • static constraint = { isbn(matches: &quot;[0-9]{9}[0-9X]&quot;) }
    • Many constraints available:
      • blank, creditcard, email, blank, nullable, matches, range, unique, url…
    • You can create your own validator
      • myField(validator: { it % 2 == 0 })
  21. No more DAOs!
    • Dynamic finder methods
      • Book. findBy Title (&quot;The Stand&quot;) Book.findBy Title Like (&quot;Harry Pot%&quot;) Book.findBy ReleaseDate Between (start, end) Book.findBy Title LikeOr ReleaseDate LessThan ( &quot;%Grails%&quot;, someDate)
    • Find by relationship
      • Book.findAllByAuthor( Author.get(1) )
    • Affect sorting
      • Book.findAllByAuthor( me, [sort: ‘title’, order: ‘asc’ ] )
  22. Querying
    • Query by example
      • Book.find ( new Book(title: ‘The Shining’) )
    • HQL queries
      • Book.find( &quot; from Book b where b.title like ‘Lord of%’ &quot; )
      • Book.find( &quot; from Book b where b.title like ? &quot;, [ ‘Lord of%’ ] )
    • Criteria builder
      • def results = Account.createCriteria() { like (&quot;holderFirstName&quot;, &quot;Fred%&quot;) and { between (&quot;balance&quot;, 500, 1000) eq (&quot;branch&quot;, &quot;London&quot;) } order (&quot;holderLastName&quot;, &quot;desc&quot;) }.list()
  23. Pain Point #2 – Services, Nav. & Pres. Logic
    • Numerous layers
    • Conf file chaos
    web.xml xwork.xml applicationContext.xml sitemesh.xml struts-config.xml validator.xml faces-config.xml tiles.xml
  24. Controllers
    • 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 = &quot;Book ${params.id} not found&quot;
    • redirect(action:list)
    • } else return [ book : book ]
    • }
    • }
    • http://localhost:8080/myapp/ book / show
  25. Services & Scheduled Tasks
    • 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 }
    • Recuring events (Quartz)
      • Intervals, or cron definitions
      • class MyJob { def cronExpression = &quot;0 0 24 * * ?&quot; def execute() { print &quot;Job run!&quot; } }
  26. Pain Point #3 – The View Layer
    • JSP cluttered with scriptlets
    • Taglibs are painful
    c.tld fmt.tld spring.tld grails.tld struts.tld
  27. The view layer
    • 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
    • Customisable layout with SiteMesh
    • Page fragments through reusable templates
    • Views under grails-app/views
  28. Groovy Server Pages
    • <html>
    • <head>
    • <meta name=&quot;layout&quot; content=&quot;main&quot; />
    • <title>Book List</title>
    • </head>
    • <body>
    • <a href=&quot; ${createLinkTo(dir:'')} &quot;>Home</a>
    • <g:link action=&quot;create&quot;> New Book</g:link>
    • <g:if test=&quot;${flash.message}&quot;>
    • ${flash.message}
    • </g:if>
    • <g:each in=&quot; ${bookList} &quot;> ${it.title} </g:each>
    • </body>
    • </html>
  29. Dynamic Tag Libraries
    • Logical : if, else, elseif
    • Iterative : while, each, collect, findAll…
    • Linking : link, createLink, createLinkTo
    • Ajax : remoteFunction, remoteLink, formRemote, submitToRemote…
    • Form : form, select, currencySelect, localeSelect, datePicker, checkBox…
    • Rendering : render*, layout*, paginate…
    • Validation : eachError, hasError, message
    • UI : richTextEditor…
  30. Write your Own Taglib
    • Yet another Grails convention
      • class My TagLib { def isAdmin = { attrs , body -> def user = attrs['user'] if(user != null && checkUserPrivs(user)) body() } }
    • Use it in your GSP
      • <g:isAdmin user=&quot;${myUser}&quot;> some restricted content </g:isAdmin>
  31. What else?
    • Custom URL mapping
    • Conversation flows
    • ORM DSL
      • http://grails.org/GORM+-+ Mapping +DSL
    • Develop with pleasure with IntelliJ IDEA
      • http:// grails.org /IDEA+ Integration
  32. Custom URL Mappings (1/2)
    • Pretty URLs in seconds
    • Custom DSL for mapping URLs to controllers, actions and views
    • Supports mapping URLs to actions via HTTP methods for REST
    • Supports rich constraints mechanism
  33. Custom URL Mappings (2/2)
    • Pretty URLs in seconds!
    • class UrlMappings { static mappings = { &quot;/product/ $id &quot;(controller: &quot;product&quot;, action: &quot;show&quot;) &quot;/$blog/ $year? /$month?/$day?&quot;(controller: &quot;blog&quot;, action: &quot;show&quot;) { constraints { year(matches: /d{4}/) } } }
  34. Conversations flows (1/2)
    • Leverages Spring WebFlow
    • Supports Spring’s scopes
      • Request
      • Session
      • Conversation
      • Flash
    • Possibly to specify services’ scope
    • DSL for constructing flows
  35. Conversations flows (2/2)
    • Example:
    • def searchFlow = { displaySearchForm { on(&quot;submit&quot;).to &quot;executeSearch&quot;   } executeSearch { action { [results: searchService. executeSearch(params.q)] } on(&quot;success&quot;).to &quot;displayResults&quot; on(&quot;error&quot;).to &quot;displaySearchForm&quot;  } displayResults() }
  36. Grails plugin system
    • Beyond the out-of-the-box experience,
    • extend Grails with plugins
    • and write your own!
  37. Plugin Extension Points
    • Extend Grails beyond what it offers!
    • What can you do with plugins?
      • Hook into the build system
      • Script the Spring application context
      • Register new dynamic methods
      • Container configuration (web.xml)
      • Adding new artefacts types
      • Auto-reload your artefacts
  38. Plenty of Plugins!
    • XFire
      • Expose Grails services as SOAP
    • Searchable
      • Integrate Lucene & Compass search
    • Remoting
      • Expose Grails services over RMI, Burlap, or REST
    • Google Web Toolkit
      • Integrate Grails with GWT for the presentation layer
    • Acegi / JSecurity
      • Secure your Grails app
    • JMS
      • Expose services as message-driven beans
  39. Sweet spot: Enterprise-readiness
    • Skills, libraries, app servers…
  40. Protect your Investment
    • Reuse
      • Existing Java libraries (JDK, 3rd party, in-house)
      • Employee skills & knowledge (both prod & soft)
      • Spring configured beans
      • Hibernate mappings for legacy schemas (but still benefit from dynamic finders)
      • EJB3 annotated mapped beans
      • JSPs, taglibs for the view
    • Deploy on your pricey Java app-server & database
    • Grails will fit in your Java EE enterprise architecture!
  41. Let’s Wrap Up
    • Summary
    • Resources
    • Q&A
  42. Summary
    • Groovy is a powerful dynamic language for the JVM, that provides agile development on the Java platform, without the impedance mismatch of other languages
      •  Groovy 1.1 out next week
    • Grails is a fully-featured web application framework based on proven technologies like Spring and Hibernate , which simplifies the development of innovative applications
      •  Grails 1.0 at the end of the month
  43. Resources
    • Grails: http://grails.org
    • Groovy: http://groovy.codehaus.org
    • Groovy blogs: http://groovyblogs.org
    • AboutGroovy: http://aboutgroovy.com
    • Mailing-lists: http://grails.org/Mailing+lists
    • G2One: http://www.g2one.com
  44. G2One, Inc.
    • Groovy & Grails at the source!
      • Graeme Rocher, Grails lead
      • Guillaume Laforge, Groovy lead
      • Plus key committers
    • Professional Services
      • Training, support, consulting
      • Custom developments
        • Connectors, plugins, etc…
  45. Q&A

+ Guillaume LaforgeGuillaume Laforge, 12 months ago

custom

1047 views, 2 favs, 1 embeds more stats

Introduction to the Grails web framework at the Iri more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 1047
    • 1045 on SlideShare
    • 2 from embeds
  • Comments 1
  • Favorites 2
  • Downloads 37
Most viewed embeds
  • 2 views on http://lyrics.filestube.com

more

All embeds
  • 2 views on http://lyrics.filestube.com

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories