Your SlideShare is downloading. ×
0
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Introduction to Grails Framework
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction to Grails Framework

4,170

Published on

Apresentação de Miguel Ping - 5º encontro PT.JUG.

Apresentação de Miguel Ping - 5º encontro PT.JUG.

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,170
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
238
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Similarities to Jboss SeamWe can see by this slide the commands syntax
  • Some constraints are mapped to DB constraints, although when removing a constraint grails do not remove the correspondent db constraint.
  • Intro to taglib, grails style. Mapping to closure. Almost no need for code in gsp.
  • Explain that Grails is Action-First
  • Talk about maturity
  • Faltou falar de: Ambientes, Testes, Scripts, GORM criteria, DSL para beans spring, Plugin Migrações
  • Configuration Files
  • Transcript

    • 1. Miguel Ping<br />Introduction to Grails Framework<br />18/03/2010<br />
    • 2. <ul><li>Small Introduction on Groovy
    • 3. Grails
    • 4. Grails = Groovy on (G)Rails
    • 5. Grails is MVC
    • 6. Powered by Spring and Hibernate
    • 7. Model/Domain Layer
    • 8. View Layer
    • 9. Controllers
    • 10. Demo</li></ul>Agenda<br />
    • 11. Groovy<br />+<br />=<br />
    • 12. Java Class<br />publicclassHelloWorld {privateString name;publicvoidsetName(String name) {this.name = name; }publicStringgetName() {return name; }publicStringgreet() {return"Hello "+ name; }publicstaticvoidmain(String[] args) {HelloWorldhelloWorld=newHelloWorld();helloWorld.setName("Groovy");System.out.println(helloWorld.greet()); }}<br />
    • 13. Groovy Class<br />publicclassHelloWorld {privateString name;publicvoidsetName(String name) {this.name = name; }publicStringgetName() {return name; }publicStringgreet() {return"Hello "+ name; }publicstaticvoidmain(String[] args) {HelloWorldhelloWorld=newHelloWorld();helloWorld.setName("Groovy");System.out.println(helloWorld.greet()); }}<br />
    • 14. <ul><li>Multiple classes per file, or even no classes at all (scripts)
    • 15. Public unless defined otherwise
    • 16. Getters and Setters by default
    • 17. String interpolation
    • 18. Semicolons are optional
    • 19. Type declarations are optional
    • 20. Return keyword is optional</li></ul>Groovy Features<br />class HelloWorld {def namedefgreet() { "Hello ${name}" }}helloWorld =newHelloWorld(name: "Groovy")println helloWorld.greet()<br />
    • 21. <ul><li>Dynamic language (everything happens at runtime)
    • 22. Dynamically typed (types are “optional”)
    • 23. Closures
    • 24. Anonymous Inner Classes (recently)
    • 25. Meta Object Protocol
    • 26. Hence, MetaClasses and all the magic
    • 27. Compiles down to bytecode
    • 28. Excellent Java Interop (Groovy can call Java and vice-versa)
    • 29. Lots of synthatic sugar
    • 30. person?.address
    • 31. def a = b ?:c</li></ul>Groovy Definition<br />
    • 32. Grails<br />+<br />=<br />
    • 33. <ul><li>Spring framework released in 2003
    • 34. SpringSource founded in 2004
    • 35. G2One (The Groovy Grails Company) founded in 2007 by the Groovy and Grails project leads
    • 36. November 2008: G2One was acquired by SpringSource
    • 37. August 2009: SpringSource was acquired by VMware for $420m
    • 38. SpringSource is now a division of VMware </li></ul>Overview<br />
    • 39. <ul><li>Grails is Groovy + Spring + Hibernate + Some nice stuff
    • 40. Heavily inspired on Rails framework
    • 41. But takes advantage of Java technology like Spring and servlets
    • 42. It means good Java (platform) integration
    • 43. Produces .war artifacts deployable in any servlet container
    • 44. Has some command-line scripts to ease the pain
    • 45. > grails generate-all MyClass
    • 46. > grails test-app -integration
    • 47. Has a plugin architecture
    • 48. > grails install-plugin jquery</li></ul>Overview<br />
    • 49. Grails is a Full Stack<br />Groovy<br />Grails<br />Sitemesh<br />Plugins<br />Hibernate<br />Other Libraries<br />Spring<br />Java Virtual Machine / JDK<br />
    • 50. Application structure<br /><ul><li>grails-appTop level source folder with Grails artifacts
    • 51. confConfiguration sources
    • 52. controlllersController layer
    • 53. domainModel layer
    • 54. i18nInternationalized Resource Bundles
    • 55. servicesService layer
    • 56. taglibDynamic Tag Libraries
    • 57. viewsGroovy Server Pages (GSP)
    • 58. web-appStylesheets, Javascript, etc
    • 59. scriptsCustom command-line scripts
    • 60. srcOther project sources
    • 61. groovyOther Groovy project sources
    • 62. javaOther Java project sources
    • 63. lib3th Party Libraries
    • 64. testUnit, Integration and Functional tests</li></li></ul><li><ul><li>POGO – Plain Old Groovy Objects
    • 65. Plus a DSL for domain constraints
    • 66. Constraints/Validations
    • 67. relationships
    • 68. belongsTo, hasMany, mappedBy
    • 69. max, min, blank, nullable, ... , custom
    • 70. Implies validation
    • 71. hasErrors(), validate()
    • 72. DB operations
    • 73. CRUD: save(), delete(), ...
    • 74. Dynamic Finders
    • 75. FindAllBy<Field> - Magick!!!</li></ul>Models<br />
    • 76. Example of a Model<br /><ul><li>class Book {static belongsTo = [author: Author] //no ID declarationString titleString isbnBigDecimal priceDate dateCreatedDate lastUpdated //CallbacksdefbeforeInsert() { dateCreated =newDate() //not really necessary } // DSL for constraintsstatic constraints = { title(blank: false, maxSize: 100) isbn(blank: false, matches: "[0-9]{13}", minSize: 13, maxSize: 13, unique: true) price(nullable: true, min: 0.0, max: 9999.99, scale: 2) }// DSL for database mappingstatic mapping = { table "books" price column: "sales_price" }}</li></li></ul><li><ul><li>A lot like JSPs
    • 77. Taglib
    • 78. Pagination, i18n, ajax, page navigation
    • 79. Hyperlinks
    • 80. <g:link controller=“<controller>” action=“<action>” </li></ul> params=“<params>”><br /><ul><li>Controller is the controller name
    • 81. Action is the closure name
    • 82. Params are available in the controller’s closure
    • 83. etc (including custom taglibs)
    • 84. Partial render/Templates
    • 85. Reusable, allows composition
    • 86. g:render
    • 87. Layouts</li></ul>Views - GSPs<br />
    • 88. Views - Taglibs<br /><ul><li>Logic and Iteration <g:if><g:else><g:elsif><g:each><g:while>
    • 89. Links and Resources</li></ul> <g:link action="show" id="${currentBook.id}">${currentBook.name}</g:link><br /><g:link controller="book" action="list">BookList</g:link><br /><ul><li>Forms and Fields</li></ul><g:textField name="title" value="${bookInstance.title}"/><br /><g:select name="author.id" from="${Author.list()}" value="${book.author.id}"/><br /><g:datePicker name="publishDate" value="${bookInstance.publishDate}"/><br /><ul><li>Do Your Own</li></ul>class SimpleTagLib {static namespace ="auth"def isAdmin = { attrs, body ->if (attrs.user.admin) out << body() }}<br /><auth:isAdmin user="${session.user}">// some restricted content</auth:isAdmin><br />
    • 90. Example of a GSP<br /><ul><li>Embedded Groovy code</li></ul><html><body><% [1, 2, 3, 4].each { num ->if (num >2) { %><p><%="Hello ${num}!"%></p><% } } %></body></html><br /><ul><li>With Tag Libraries</li></ul><html><body><g:each in="${[1, 2, 3, 4]}" var="num"><g:if test="${num > 2}"><p>Number ${num}</p></g:if></g:each></body></html><br />
    • 91. <ul><li>Handle the web request
    • 92. Grails is action-first, it means the controller runs before the view
    • 93. Spring-managed beans
    • 94. Can hook up with another beans through Spring DI
    • 95. Idiom</li></ul>params variable<br />holds request parameters<br /><ul><li>render
    • 96. redirect,
    • 97. return [beanName: bean]</li></ul>returns some data to the view<br />Controllers<br />
    • 98. Example of a Controller<br /><ul><li>class BookController { //will match http://myApp:8080/book/static allowedMethods = [save: "POST", update: "POST", delete: "POST"]// default actiondef index = { redirect(action: "list", params: params) }def list = {//by default, we go to the “list.gsp” [bookInstanceList: Book.list(params), bookInstanceTotal: Book.count()] }defedit = { //params is a Map with an ‘id’ keydef bookInstance =Book.get(params.id)return [bookInstance: bookInstance] }def save = {def bookInstance =newBook(params)if (bookInstance.save()) { redirect(action: "show", id: bookInstance.id) }else { render(view: "create", model: [bookInstance: bookInstance]) } }</li></li></ul><li>Spring glues everything<br />Spring IoC / DI<br />We can write custom beans and wire everything together<br />Spring MVC<br />Spring Transactions<br />Spring i18n<br />Spring Glue<br />
    • 99. <ul><li>Lots and lots of them
    • 100. Spring Security / Acegi
    • 101. RIA/AJAX: RichUI & GrailsUI
    • 102. Testing (eg: Canoo, EasyB, etc)
    • 103. Debugging plugins (eg: simple dashboard)
    • 104. Optimization plugins (eg: js minifier)
    • 105. Deployment plugins (eg: google-app-engine, amazon)
    • 106. Other
    • 107. Multi-tenant
    • 108. Paypal
    • 109. Openid
    • 110. SpringWS
    • 111. GWT</li></ul>Plugins<br />
    • 112. 2 classes<br />Constraints<br />Relations<br />Scaffolding<br />Dynamic Finders<br />View<br />Some GSP navigation<br />Controllers<br />CRUD<br />AJAX<br />Test Drive<br />
    • 113. Questions<br />
    • 114. <ul><li>grails create-app [app name]
    • 115. grails create-controller [controller name]
    • 116. grails create-domain-class [class name]
    • 117. grails create-service [service name]
    • 118. grails create-unit-test [test name]
    • 119. grails create-tag-lib [taglib name]
    • 120. grails generate-all [class name]
    • 121. grails generate-views [class name]</li></ul>Command line scripts - development<br />
    • 122. <ul><li>grails clean
    • 123. grails compile
    • 124. grails console
    • 125. grails doc
    • 126. grails install-plugin
    • 127. grails run-app
    • 128. grails war</li></ul>Command line scripts - lifecycle<br />
    • 129. <ul><li>conf/DataSource.groovy
    • 130. Database connections
    • 131. conf/UrlMapping.groovy
    • 132. Routing
    • 133. conf/BootStrap.groovy
    • 134. Bootstrap file
    • 135. conf/Config.groovy
    • 136. Configurations (MIME mappings, more…)</li></ul>Important Files<br />
    • 137. <ul><li>LessThan
    • 138. LessThanEquals
    • 139. GreaterThan
    • 140. GreaterThanEquals
    • 141. Between
    • 142. Like
    • 143. Ilike (i.e. ignorecase like)
    • 144. IsNotNull
    • 145. IsNull
    • 146. Not
    • 147. Equal
    • 148. NotEqual
    • 149. And
    • 150. Or</li></ul>Dynamic Finders<br />

    ×