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.

Like this presentation? Why not share!

Introduction to Groovy and Grails

on

  • 6,471 views

Introduction to Groovy & Grails given at the Devnology Community Day on 6th of November 2010.

Introduction to Groovy & Grails given at the Devnology Community Day on 6th of November 2010.

Statistics

Views

Total Views
6,471
Views on SlideShare
6,460
Embed Views
11

Actions

Likes
7
Downloads
248
Comments
0

2 Embeds 11

http://developer.eltropy.com 7
http://devnology.nl 4

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

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
  • <br />
  • <br />
  • Remember the audience that programming languages evolve and that no programming language is better then the other. They are used to communicate in their timeframe and created for needs that exist at that time. We will not discuss why one language is better then the other try to appreciate the differences and grasp the concepts instead of focussing on the vocabulary. <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • Demo of converting Java program to Groovy <br /> <br /> http://groovy.dzone.com/news/java-groovy-few-easy-steps <br /> <br /> - Start Groovy Console: groovyConsole <br /> - Copy Text from HelloWorld.java <br /> <br /> Steps: <br /> - remove semi colons and public keyword <br /> - implement the GString and return statement <br /> - set name as property, remove private field and getters and setters <br /> - remove System.out <br /> - implement dynamic typing <br /> - implement as script <br /> <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Introduction to Groovy and Grails Introduction to Groovy and Grails Presentation Transcript

  • Introduction to Groovy & Grails Devnology Community Day Sat 6 Nov 2010 een beetje anders, een groot verschil
  • About me ๏ Marco Pas - Deelnemer at IHomer ๏ Travelled from Chemistry IT to Logistics to Consulting and now arrived at being self-employed. ๏ Just a guy who likes to try out things and learn interesting concepts & technologies! een beetje anders, een groot verschil 2
  • “There is no programming language–no matter how structured–that will prevent programmers from making bad programs.” (Larry Flon)
  • Plans for today Thanks to: Guillaume Laforge Marcel Overdijk een beetje anders, een groot verschil 4
  • Introduction to Groovy The start ๏ James Strachan to Bob McWhirter in 2003: > Wouldn’t it be “groovy” if we could have native syntax for lists, maps and regexs in Java like in most scripting languages? > Wouldn’t it be “groovy” if we could have duck typing in Java? > Wouldn’t it be “groovy” if we had closures and properties in Java? een beetje anders, een groot verschil 5
  • Introduction to Groovy According to “Groovy is an object-oriented programming language for the Java platform. It is a dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk. It can be used as a scripting language for the Java Platform.” -- Wikipedia een beetje anders, een groot verschil 6
  • Introduction to Groovy Some notes & remarks ๏ History ๏ Bumpy Ride ๏ “Head Honcho” Guillaume Laforge ๏ TIOBE Index ๏ When to use it?? een beetje anders, een groot verschil 7
  • Introduction to Groovy Groovy is everywhere ๏ Integrated in Open Source projects > Spring, JBoss SEAM, ServiceMix, Mule, Oracle OC4J, JMeter, ... ๏ Integrated in mission-critical applications > Mutual of Omaha, US Fortune 500 insurance company > US National Cancer Institute ๏ Integrated in commercial products > IBM WebSphere Smash, SAP Composition on Grails > Oracle Data Integrator, Oracle Fusion (ADF) een beetje anders, een groot verschil 8
  • Introduction to Groovy Groovy resources een beetje anders, een groot verschil 9
  • Introduction to Groovy Features at a glance ๏ Groovy is an agile and dynamic language for the JVM ๏ Builds upon the strengths of Java ๏ Seamlessly integrates with all existing Java objects and libraries ๏ Compiles down to bytecode ๏ With a MOP = Meta-Object Protocol ๏ optional typing vs dynamic typing vs static typing ๏ No static typing or is there? [Groovy++] een beetje anders, een groot verschil 10
  • Introduction to Groovy Features at a glance ๏ Closures: reusable / assignable code blocks ๏ Properties: auto-generated getters / setters ๏ Multimethods: call the right method for the right type void doIt(Object o) {} // Java void doIt(String s) {} // Groovy Object o = "foo"; ๏ Useful wrapper APIs: SQL, XML, Swing, templates, JMX... een beetje anders, een groot verschil 11
  • Groovy & Grails Java integration ๏ Groovy generates Java bytecode for the JVM > Same strings, same regex > Same APIs — JDK, collections, 3rd party, etc. > Same security model, same threading model > Same OO concepts JInterface GInterface <<implements>> <<implements>> > Joint-compilation GClass JClass JClass GClass een beetje anders, een groot verschil 12
  • Introduction to Groovy Let’s get started ๏ Go to http://groovy.codehaus.org/Download ๏ Download the latest version ๏ Unzip the archive, set GROOVY_HOME ๏ Add $GROOVY_HOME/bin to your path ๏ ... ๏ ... ๏ You’re ready! een beetje anders, een groot verschil 13
  • Introduction to Groovy Tools at your disposal ๏ Shell and console: groovysh and groovyConsole ๏ An Ant task, a Maven plugin (GMaven) ๏ A joint compiler ๏ Lets you compile both Groovy and Java together! ๏ IDE support een beetje anders, een groot verschil 14
  • Introduction to Groovy From Java to Groovy ๏ A normal Java program public class HelloWorld { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println(helloWorld.greet()); } } een beetje anders, een groot verschil 15
  • Introduction to Groovy From Java to Groovy ๏ A valid Groovy program public class HelloWorld { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println(helloWorld.greet()); } } een beetje anders, een groot verschil 16
  • Introduction to Groovy From Java to Groovy ๏ But hey? ๏ Where are the steroids? een beetje anders, een groot verschil 17
  • Introduction to Groovy Demo Time ๏ Groovy Shell ๏ Groovy Console D em oT ime een beetje anders, een groot verschil 18
  • Introduction to Groovy From Java to Groovy ๏ A Groovier program class HelloWorld { def name def greet() { "Hello ${name}" } } def helloWorld = new HelloWorld(name: "Groovy") println helloWorld.greet() ๏ Dynamic types using the def keyword ๏ Everything in Groovy is public unless defined otherwise ๏ Automatic getters and setters ๏ Semicolons at end-of-line are optional ๏ Variable interpolation through GStrings een beetje anders, een groot verschil 19
  • Introduction to Groovy Native Syntax Constructs ๏ Lists > def numbers = [1, 2, 3, 4, 5] ๏ Maps/Hashes > def map = [NL: "Netherlands", BE: "Belgium"] ๏ Ranges > def allowedAges = 18..65 ๏ Regular expressions > def whitespace = ~/s+?/ een beetje anders, een groot verschil 20
  • Introduction to Groovy GStrings ๏ GStrings are interpolated strings > Placeholder variables are replaced > You can have multiline strings def person = "John" def letter = """${new Date()} Dear ${person}, this is a Groovy letter!""" println letter een beetje anders, een groot verschil 21
  • Introduction to Groovy Closures ๏ A reusable / assignable block of code ๏ delimited by curly braces ๏ can take parameters ๏ can be passed as parameters to methods, or inline new File("f.txt").eachLine { line -> println line } def printer = { println it } new File("f.txt").eachLine( printer ) een beetje anders, een groot verschil 22
  • Introduction to Groovy Iteration ๏ Looping > for (i in list) { println i } ๏ Looping with closures > list.each { println it } een beetje anders, een groot verschil 23
  • Introduction to Groovy Time savers ๏ The Groovy Truth > def line = ""; assert !blank • false as line is an empty string > def numbers = []; assert !empty • false as numbers is an empty collection > def digit = 0; assert !digit • false as 0’s are false een beetje anders, een groot verschil 24
  • Introduction to Groovy Time savers ๏ Safe graph navigation > def postalCode = user?.address?.postalCode?.toUpperCase() == null > Java: String postalCode = null; if (user != null) { Address address = user.getAddress(); if (address != null) { postalCode = address.getPostalCode(); if (postalCode != null) { postalCode = postalCode.toUpperCase(); } } } ๏ Elvis operator / Ternary operator > def name = user.name ?: "Unknown" > Java: def displayName = user.name ? user.name : "Anonymous" een beetje anders, een groot verschil 25
  • Introduction to Groovy Meta Programming ๏ You can add methods and properties to any Object at runtime ๏ You can intercept method calls and property access (similar to AOP) def s = "Hello Groovy" println s println s.toUpperCase() // standard JDK method String.metaClass { toMixedCase { delegate.toUpperCase() } // add method toUpperCase { delegate.toLowerCase() } // override existing method multiply { i -> delegate * i } // add method with argument } println s.toMixedCase() println s.toUpperCase() println s.multiply(3) een beetje anders, een groot verschil 26
  • Introduction to Groovy The GDK - Groovy Dev Kit ๏ Groovy “decorates” existing JDK APIs > IO, JDBC, Collection etc.. new File("f.txt").eachLine { println it } (1..100).findAll { it % 2 == 1 } speakers.groupBy { it.lastname } Thread.start { /* code to be executed */ } een beetje anders, een groot verschil 27
  • Introduction to Groovy JDBC made easy ๏ JDBC made easy def sql = Sql.newInstance(url, usr, pwd, driver) sql.execute("insert into table values ($foo, $bar)") sql.execute("insert into table values(?,?)", [a, b]) sql.eachRow("select * from USER") { print it.name } def list = sql.rows("select * from USER") een beetje anders, een groot verschil 28
  • Introduction to Groovy Parsing XML ๏ With this multiline string XML fragment def xml = """ <languages> <language name="Groovy"> <feature coolness="low">SQL</feature> <feature coolness="high">Template</feature> </language> <language name="Perl"/> </languages>""" ๏ Navigate your XML graph as an object graph! def root = new XmlParser().parseText(xml) println root.language.feature[1].text() root.language.feature .findAll{ it['@coolness'] == "low" } .each{ println it.text() } een beetje anders, een groot verschil 29
  • Introduction to Groovy Questions? ? een beetje anders, een groot verschil 30
  • Introduction to Grails Grails een beetje anders, een groot verschil 31
  • Introduction to Grails Agenda ๏ A bit of history and background ๏ The Grails stack ๏ Getting started [with scaffolding] ๏ The various layers > Model > Controller > View > Service ๏ Services ๏ Plugins een beetje anders, een groot verschil 32
  • Introduction to Grails Recurring challenges ๏ When you start a project, you have to setup everything > Wire all components together, (re)think & implement application layers > Define tools & technologies > Create DAO, DTO, interfaces & implementations > Development cycle takes ages, Compile, Package, Deploy ๏ We have all the tools at our disposal to change that but no ‘prefab’ solution een beetje anders, een groot verschil 33
  • Introduction to Grails The essence of Grails Guillaume Laforge on the Groovy lists in 2005: Ruby on Rails is all the rage these days, but you compromise on your past investment, if you’re a Java shop: developer and IT team skills, training, app servers, the great JVM platform, third- party libraries... Can’t we leverage Groovy and proven technologies like Spring and Hibernate to bring the “Convention over Configuration” paradigm on the Java platform, without compromising on your investment? een beetje anders, een groot verschil 34
  • Introduction to Grails Understanding Grails - The Goal Simplify enterprise Java web development & take it to the next level of abstraction. Retain flexibility to drop down into the underlying technologies and utilize their richness and maturity. een beetje anders, een groot verschil 35
  • Introduction to Grails Agenda ๏ A bit of history and background ๏ The Grails stack ๏ Getting started [with scaffolding] ๏ The various layers > Model > Controller > View > Service ๏ Plugins een beetje anders, een groot verschil 36
  • Introduction to Grails From 10.000 Feet ๏ Grails is an MVC action-based framework ๏ Grails follows good principles popularized by Rails > CoC: Convention over Configuration > DRY: Don’t Repeat Yourself ๏ The essence of Rails but with tight integration with the Java platform to protect your investment! een beetje anders, een groot verschil 37
  • Introduction to Grails From 1.000 Feet ๏ Built on the shoulders of Giants > the JVM, the Java EE specs, existing app servers, and... > Spring: IoC, DI, Spring MVC, Spring WebFlow > Hibernate: Object-Relational Mapping > SiteMesh: page layout and composition > Quartz: for job scheduling > Tomcat and HSQLDB: for fast development cycles ๏ Productive out of the box with a full development stack een beetje anders, een groot verschil 38
  • Groovy & Grails Grails Stack Grails Other JEE Spring Hibernate Libraries Groovy Java Development Kit Java Language (JDK) Java Virtual Machine een beetje anders, een groot verschil 39
  • Introduction to Grails Agenda ๏ A bit of history and background ๏ The Grails stack ๏ Getting started [with scaffolding] ๏ The various layers > Model > Controller > View > Service ๏ Plugins een beetje anders, een groot verschil 40
  • Introduction to Groovy Let’s get started ๏ Go to http://www.grails.org/Download ๏ Download the latest version ๏ Unzip the archive, set GRAILS_HOME ๏ Add $GRAILS_HOME/bin to your path ๏ You’re ready! ๏ Next step: grails create-app een beetje anders, een groot verschil 41
  • Groovy & Grails Grails Command Line ๏ grails create-app ๏ grails create-domain-class ๏ grails create-controller ๏ grails generate-all ๏ grails install plugin ๏ grails run-app ๏ grails test-app ๏ grails war ๏ grails console ๏ ... ๏ Custom commands (scripts) can be added to project een beetje anders, een groot verschil 42
  • Groovy & Grails Grails Project Breakdown ๏ grails-app Top level source folder with Grails artifacts > conf Configuration sources > controlllers Controller layer > domain Model layer > i18n Internationalized Resource Bundles > services Service layer > taglib Dynamic Tag Libraries > views Groovy Server Pages (GSP) ๏ web-app Stylesheets, Javascript, ... ๏ scripts Custom command-line scripts ๏ src Other project sources > groovy Other Groovy project sources > java Other Java project sources ๏ lib 3th Party Libraries ๏ test Unit, Integration and Functional tests een beetje anders, een groot verschil 43
  • Introduction to Grails Agenda ๏ A bit of history and background ๏ The Grails stack ๏ Getting started [with scaffolding] ๏ The various layers > Model > Controller > View > Service ๏ Plugins een beetje anders, een groot verschil 44
  • Introduction to Grails MVC/Layers een beetje anders, een groot verschil 45
  • Introduction to Grails Model = GORM ๏ GORM (Grails Object Relational Mapping) > Domain Model is set of POGOs > Transparently Mapped > Legacy Schema with GORM DSL > No Hibernate config files, but you can bring your existing ones if needed ๏ Auto Timestamping, Constraints, Mapping ๏ Events ๏ Relations ๏ Queuring ๏ Basic CRUD methods, Dynamic Finders een beetje anders, een groot verschil 46
  • Introduction to Grails Domain Classes class Contact { String name String email } een beetje anders, een groot verschil 47
  • Introduction to Grails Timestamp, Constraints, Mapping class Contact { String name String email Date dateCreated // auto timestamp You can also define Date lastUpdated // auto timestamp your own constraints! static constraints = { // constraints name(blank:false) email(blank:true, email:true, size:5..20) } static mapping = { // Custom ORM Mapping table "contactTBL" name column: "contact_name" } } een beetje anders, een groot verschil 48
  • Introduction to Grails Events class Contact { String name String email ~ code: timestamps/constraints/mapping ~ def beforeInsert = { log.info "inserting contact: ${name}" } def beforeUpdate = { log.info "updating contact: ${name}" } // beforeInsert, beforeUpdate, beforeDelete // afterInsert, afterUpdate, afterDelete } een beetje anders, een groot verschil 49
  • Introduction to Grails Relations class Contact { String name String email ~ code: timestamps/constraints/mapping/events ~ User user static belongsTo = User //optional in this case! } class User { String userId String password one-to-one ~ code: timestamps/constraints ~ many-to-one one-to-many static hasMany = [contacts: Contact] many-to-many } een beetje anders, een groot verschil 50
  • Introduction to Grails Basic CRUD methods // read Contact c = Contact.get(1) // create Contact c1 = new Contact(name: "John Doe", email: "john.doe@doe.com").save() Contact c2 = new Contact() c2.name = "Jane Doe" c2.email = "jane@doe.com" c2.save() // update Contact c = Contact.get(1) c.name = "Foo Bar" c.save() // delete Contact c = Contact.get(1) c.delete() een beetje anders, een groot verschil 51
  • Groovy & Grails Querying with GORM // query all contacts def contacts = Contact.list() // pagination def contacts = Contact.list(max: 10, offset: 20) // sorting def contacts = Contact.list(order: "name", sort: "desc") // pagination and sorting def contacts = Contact.list(max: 10, offset: 20, order: "name", sort: "desc") een beetje anders, een groot verschil 52
  • Groovy & Grails GORM Dynamic Finders ๏ FindBy (first result) ๏ FindAllBy (all results) ๏ Comparators > LessThan, LessThanEquals, GreaterThan, GreaterThanEquals, Like, Ilike, NotEqual, InList, Between, IsNotNull, IsNull Where is my DAO? def contact = Contact.findByName("John Doe") def contacts = Contact.findAllByTitleLike("J%") def contact = Contact.findByNameAndEmail( "John Doe", "john.doe@doe.com") een beetje anders, een groot verschil 53
  • Groovy & Grails Criteria and HQL // using criteria builder def criteria = Contact.createCriteria() def contacts = criteria { ilike("name", "J%") and { between("age", 26, 35) // additional criteria! } order("name", "desc") } contacts.eachWithIndex { contact, index -> println "${index} - ${contact.name}" } // using HQL (Hibernate Query Language) def contacts = Contact.findAll("from Contact as c where c.name like ?", ["Joh%"]) een beetje anders, een groot verschil 54
  • Introduction to Grails Agenda ๏ A bit of history and background ๏ The Grails stack ๏ Getting started [with scaffolding] ๏ The various layers > Model > Controller > View > Service ๏ Plugins een beetje anders, een groot verschil 55
  • Introduction to Grails Controllers ๏ In the controller directory, name ending with “Controller” > http://myserver:8080/app/<controller>/<action> ๏ Action based Reload!! ๏ Responsible for handling requests ๏ Handy things at your disposal > redirect, chain, render een beetje anders, een groot verschil 56
  • Introduction to Grails Controller databinding ๏ Easy databinding for form fields > contact.properties = params ๏ Controllers return Maps as models for the view to render > return [contacts: Contact.list()] > return [contact: Contact.get(params.id)] ๏ Support interceptors & content negotiation een beetje anders, een groot verschil 57
  • Introduction to Grails Example Controller class <name>Controller { def <actionname> = { // inspect incoming params // execute controller logic Skeleton // prepare model return <model> } } class StartController { def index = { render "Hello everybody" Render text } } class ContactController { def list = { return [contacts: Contact.list()] Returning a model } } een beetje anders, een groot verschil 58
  • Introduction to Grails Controllers class ContactController { def list = { Controller return [contacts: Contact.list()] } } <ul> <g:each in="${contacts}"> <li> View ${contact.name} - ${contact.email} </li> </g:each> </ul> een beetje anders, een groot verschil 59
  • Introduction to Grails Actions in the wild! class ContactController { def index = {} // default action when otherwise noted def list = {} def create = {} def save = {} def update = {} def delete = {} def show = {} def save = {} def pleaseDearGrailsDoSomethingForMe = {} } You are free in defining your own actions een beetje anders, een groot verschil 60
  • Introduction to Grails Example Controller class ContactController { def index = { redirect( action: 'list', params: params) } def list = { [contacts: Contact.list(params), contactCount: Contact.count()] } def create = { Contact contact = new Contact() contact.properties = params return [contact: contact] } def save = { Contact contact = new Contact(params) if(contact.save()) { redirect(action: 'show', id: contact.id) } else { log.error "Error: ${contact.errors}" flash.error = "Error occurred when saving a contact" render(view: 'create', model: [contact: contact]) } } ... ... } een beetje anders, een groot verschil 61
  • Introduction to Grails Interceptors ๏ Before and After Interceptors ๏ Triggered by all actions inside a controller class UserController { def index = { } def beforeInterceptor = { // do something log.info("Start - action ${actionName} - ${params}") } def afterInterceptor = { // do something } } <type>Interceptor = [action:<methodName>, only:[action] <type>Interceptor = [action:<methodName>, except:[action] een beetje anders, een groot verschil 62
  • Introduction to Grails XML Response // manual way def list = { def contacts = Contact.list() render(contentType: 'text/xml') { contacts { for(contact in contacts) { contact(name: c.name) contact(email: c.email) } } } } // automatic XML marshalling def list = { render Contact.list() as XML } een beetje anders, een groot verschil 63
  • Introduction to Grails Content Negotiation ๏ You can use HTTP Accept Header ๏ You can use format request parameter (/book/list? format=xml) ๏ You can use URI extension (/book/list.xml) ๏ Use the withFormat method to deal with different formats class ContactController { def list = { def contacts = Contact.list() withFormat { html contacts: contacts js { render "allert('hello')" } xml { render contacts as XML } } } } een beetje anders, een groot verschil 64
  • Introduction to Grails Agenda ๏ A bit of history and background ๏ The Grails stack ๏ Getting started [with scaffolding] ๏ The various layers > Model > Controller > View > Service ๏ Services ๏ Plugins een beetje anders, een groot verschil 65
  • Introduction to Grails View ๏ The view tier is essentially composed of two things > Groovy Server Pages > Similar to JSPs > But with GString interpolation ๏ The Grails Tag Libraries > Useful existing tag libraries > So easy to write your own! ๏ Templates, URL mapping, conversations and more een beetje anders, een groot verschil 66
  • Introduction to Grails View Example <html> <head> <meta name="layout" content="main" /> <title>Contact 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="${contacts}"> ${it.title} </g:each> </body> </html> een beetje anders, een groot verschil 67
  • Introduction to Grails Views ๏ Groovy Server Pages (GSP) > Similar like technologies like JSP and ASP > A mix of markup and GSP tags > Groovy code can be embedded, but is discouraged > Use Tag Librariesembedded groovy code %> <% instead! def show = { Controller [contact: Contact.get(params.id)] } <%= contact.name %> View een beetje anders, een groot verschil 68
  • Introduction to Grails Views and Tag Libraries ๏ Embedded Groovy code <html> <body> <% [1, 2, 3, 4].each {num -> if (num > 2) { %> <p><%= "Hello ${num}!" %></p> <% } } %> </body> </html> ๏ Use Tag Libraries instead <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> een beetje anders, een groot verschil 69
  • Introduction to Grails Core Tag Libraries ๏ Logic and Iteration <g:if> <g:else> <g:elseif> <g:each> <g:findAll> <g:collect> ... ๏ Links and Resources <g:link action="show" id="${contact.id}">${contact.name}</g:link> <g:link controller="contact" action="list">Contact List</g:link> ๏ Forms and Fields <g:textField name="title" value="${contact.title}" /> <g:datePicker name="birthday" value="${contact.birtdate}" /> ๏ Formatting ๏ Ajax Also very easy to write your own! ๏ and more... Validation, UI een beetje anders, een groot verschil 70
  • Introduction to Grails Services ๏ Don’t put core/reusable logic in controllers, but instead use the service layer ๏ Transactional by default, can be scoped ๏ Declare your service and it will be injected! No need for XML configuration class ContactService { static scope = session // prototype, request, ... static transactional = true Contact[] getContacts() { Contact.list() as Contact } def doSomething() { // please implement or delete me :) } } een beetje anders, een groot verschil 71
  • Introduction to Grails Agenda ๏ A bit of history and background ๏ The Grails stack ๏ Getting started [with scaffolding] ๏ The various layers > Model > Controller > View > Service ๏ Plugins een beetje anders, een groot verschil 72
  • Introduction to Grails Plugins ๏ Grails is built on top of a core plugin system ๏ Plugins can provide basic artifacts > Domain Classes, Tag Libraries, Services, ... ๏ Plugins can hook into runtime configuration ๏ Plugins can add dynamic methods at runtime een beetje anders, een groot verschil 73
  • Introduction to Grails Plugins ๏ 500+ plugins available > Testing: Fitnesse, Selenium > Rich Client / Ajax: YUI, JQeury, Ext-JS, GWT, Vaadin > Web Services: XFire, Remoting, CXF > Security: Spring Security, Shiro, Spring WS > Search: Compass, Searchable > Navigation, Wicket, LiquiBase, Commentable, LDAP, Quartz, Mail, Taggable, Rateable, Cache, Terracotta, Jetty, Tomcat 500+ plugins! Process needs some improvement! een beetje anders, een groot verschil 74
  • Introduction to Grails What did i miss? ๏ Grails WebFlow ๏ Templates for reusing view logic and presentation ๏ Internationalization ๏ Filters ๏ SiteMesh layouts and page components ๏ Handling of REST style architectures ๏ Webservice SOAP handling ๏ Unit and Interaction testing een beetje anders, een groot verschil 75
  • Introduction to Grails Summary ๏ Grails is not just a web framework, but a full-blown development stack ๏ Grails is built on proven rock-solid technologies ๏ Grails brings back the productivity to Java developers ๏ Grails is a new weapon for the war on Java complexity It’s also damn fun :) een beetje anders, een groot verschil 76
  • Introduction to Grails Questions !? een beetje anders, een groot verschil 77
  • een beetje anders, een groot verschil