Slideshare.net (beta)

 
Post: 
Myspace Hi5 Friendster Xanga LiveJournal Facebook Blogger Tagged Typepad Freewebs BlackPlanet gigya icons



All comments

Add a comment on Slide 1

If you have a SlideShare account, login to comment; else you can comment as a guest


Showing 1-50 of 5 (more)

Grails 0.3-SNAPSHOT Presentation WJAX 2006 English

From hansamann, 1 year ago

English Version. Audio will be published at grails.org/Tutorials.

5921 views  |  2 comments  |  5 favorites  |  3 embeds (Stats)
 
 
 

Groups/Events

Not added to any group/event

 
 

Privacy InfoNew!

This slideshow is Public

 
Embed in your blog
Embed (wordpress.com)
custom

Slideshow Statistics
Total Views: 5921
on Slideshare: 5895
from embeds: 26* * Views from embeds since 21 Aug, 07

Slideshow transcript

Slide 1: GRAILS RAPID WEB APPLICATION DEVELOPMENT MADE EASY

Slide 2: About: Sven Haiges • Actionality Deutschland GmbH • Senior Java Developer • Diplom-Informatiker (FH), MBA • My personal framework evolution: Struts, JSF, Spring MVC, GRAILS • Since Juli 2006: Grails Podcast, Grails Screencasts 2

Slide 3: Goals • What is Grails & how do I create my first Grails app? • What are the powerful cornerstones of Grails? • Which features does Grails provide out of the box? • Next Steps @ Home/Work 3

Slide 4: Agenda Basics Foundations MVC Features Roadmap Your Next Steps 4

Slide 5: Grails Basics 5

Slide 6: Grails MVC • Grails is an MVC Web Framework • Inspired by Ruby on Rails • Uses the powerful Groovy Scripting Language • Convention Over Configuration • Don't Repeat Yourself (DRY) 6

Slide 7: Grails History & Team • Started by Groovy enthusiasts: Guillaume LaForge, Steven Devijver and Graeme Rocher (current project lead) • 0.1 was out March 29th, 2006 • Current Team: Graeme Rocher, Marc Palmer, Dierk Koenig, Steven Devijer, Jason Rudolph, Sven Haiges... YOU! 7

Slide 8: Using Grails • Standalone • Configuration details are hidden • 0..100 in no time! • Integrate with existing applications • Still use the flexibility of Grails for existing DB-Schemas, HBM-Mappings, Spring Configuration, etc. • Pimp your app! 8

Slide 9: Powerful Foundations • Foundations • Groovy: 1st class integration with Java Platform and all Java Code you have ever written! • Spring: IoC, Spring MVC, WebFlow, ... • Hibernate: powerful persistence Layer • SiteMesh: flexible layout framework 9

Slide 10: Installing Grails • No previous Groovy installation needed, just a Java VM 1.4+ (but does not hurt :-) • grails.org/Installation • Download, extract, set GRAILS_HOME, add bin to PATH, run it! • Type „grails“ to verify it works 10

Slide 11: Your First Grails App • „grails create-app“ • „cd appName” • „grails run-app“ • „grails create-domain-class“, edit class • „grails generate-all“ • „grails run-app“ 11

Slide 12: Grails Foundations 12

Slide 13: Spring • Spring Framework is used to hold everything together • You can specify your own Spring Beans for injection into Controllers, Services, Jobs in spring/resources.xml • Good to know: a Grails app is an Spring MVC app... Spring Webflow to be used in future 13

Slide 14: Hibernate • Hibernate is the de facto standard for O/R Mapping • Grails maps your Domain Classes automatically, even creates and exports the schema to the database • 1:n & m:n supported! • Great flexibility: use your own HBM files for legacy database schemas! 14

Slide 15: SiteMesh • SiteMesh is a powerful Layout Framework and integrated into Grails • grails-app/views/layout/main.gsp is the standard layout file • This meta element in a head of a gsp file links it with the “main” layout: <meta name="layout" content="main" /> 15

Slide 16: Grails Philosophy • Reuse (see foundations) • No “reinventing the wheel” • Coding by Convention • without being locked into a single solution! • Domain-Centric, not DB-Centric • DRY 16

Slide 17: Grails MVC 17

Slide 18: Model class Book { String title } • Above is a Domain Class • .groovy files living in grails-app/domain • Persistent • id, version, equals, hashCode, toString is generated automatically, but can be overridden 18

Slide 19: Model > grails create-domain-class • You will typically use this convenience target to create Domain Classes • Will ask you for the name, make it uppercase if you forget 19

Slide 20: Model class Book { Author author String title } • 1:1 mapping with Author • Specify the “owning side” with this class Book { def belongsTo = Author Author author String title } 20

Slide 21: Model class Author { def hasMany = [ books : Book ] String name } • 1:n mapping: Author has many Books • Property “books” created automatically • Same for adder method: author.addBook(new Book(title:'Grails')) author.save() 21

Slide 22: Model • m:n possible, too! • BelongsTo defines “owning side” class Book { def belongsTo = Author def hasMany = [authors:Author] } class Author { def hasMany = [books:Book] } 22

Slide 23: Model • Constraints defined via constraints closure • Affects generation of views, too! class User { String login String password String email Date age static constraints = { login(length:5..15,blank:false,unique:true) password(length:5..15,blank:false) email(email:true,blank:false) age(min:new Date(),nullable:false) } } 23

Slide 24: Model • Dynamic Finder Methods def results = Book.findByTitle("The Stand") results = Book.findByTitleLike("Harry Pot%") results = Book.findByReleaseDateBetween( firstDate, secondDate ) results = Book.findByReleaseDateGreaterThan( someDate ) • You can also use Query by Example (QBE) the Hibernate Criteria Builder, or direct HQL queries! 24

Slide 25: Model • Database configuration is done in grails-app/conf directory • DevelopmentDataSource.groovy • ProductionDataSource.groovy • TestDataSource.groovy • If you hit “grails run-app” the dev datasource is the default 25

Slide 26: Model class DevelopmentDataSource { boolean pooling = true // one of 'create', 'create-drop','update' //String dbCreate = "create-drop" String url = "jdbc:postgresql://localhost:5432/act_dev" String driverClassName = "org.postgresql.Driver" String username = "dev" String password = "devpw" def logSql = true //enable logging of SQL generated by Hibernate } • “grails war” creates your deployment war file with the production datasource 26

Slide 27: Model • BootStrap files are picked up at startup and can be used to create initial (test) data class CompanyBootStrap { def init = { servletContext -> //Delete all data in the tables that we work on Company.executeUpdate("delete Company") //now create the test data Company c1 = new Company(name:'bmw') c1.addUser(new User(name:'herbert', admin:true, ...)) .save() } ... 27

Slide 28: View • Groovy Server Pages(GSP) or JavaServer Pages (JSP) • TagLibs for both, but GSP is groovin' • All views are in the grails-app/views directory • Generate views for your domain class: “grails generate-views” 28

Slide 29: View • Example GSP / uses “main” Layout <html> <head> <meta name="layout" content="main" /> <title>BlogEntry List</title> </head> <body> <div class="nav"> <span class="menuButton"> <g:link controller="authentication" action="viewControllers" >Home</g:link></span> <span class="menuButton"><g:link action="create">New BlogEntry</g:link></span> </div> <div class="body"> ... </div> ... 29

Slide 30: View • Dynamic Tag Libraries • Tags are fun again! • “grails create-taglib” • A plain *TagLib.groovy file in grails- app/taglib • As with GSPs & Controllers: no server restart! 30

Slide 31: View • TagLib example (“simple” tag) class MyTagLib { includeJs = { attrs -> out << "<script src='scripts/${attrs['script']}.js' />" } } • OutputStream is available via “out” • All attributes are in the attrs map • Usage of GStrings keeps tags readable 31

Slide 32: View • Logical and iterative tags just as easy. • You can even call tags as “methods” within GSP – here used as normal tag: <g:hasErrors bean="${book}" field="title"> <span class='label error'>There were errors on the book title</span> </g:hasErrors> • Or as method: <span id="title" class="label ${hasErrors(bean:book,field:'title','errors')}">Title</span> 32

Slide 33: View • Creating markup from tags is a piece of cake: def dialog = { attrs, body -> mkp { div('class':'dialog') { body() } } } • Above example uses a Groovy MarkupBuilder 33

Slide 34: Controller • All controllers are mapped to the Grails dispatcher servlet • Create a new controller via: “grails create-controller” • Or generate the controller based on an existing Domain Class: “grails generate-controller” 34

Slide 35: Controller • Default Mapping Convention http://.../appName/controller/action/id • Some properties automatically available • flash – map stores messages for next request • log - a Log4J logger instance • params – map with all request parameters • request/response/servletContext etc. 35

Slide 36: Controller • Example generated controller: class AdvertisementController { def index = { redirect(action:list,params:params) } def list = { [ advertisementList: Advertisement.list( params ) ] } def show = { [ advertisement : Advertisement.get( params.id ) ] } ... 36

Slide 37: Controller • You can also use dynamic scaffolding: class BookController { def scaffold = Book } • list/show/edit/delete/create/save/ update “dynamically” available • You can still override actions • “grails generate-all” creates all views and all controller actions for a domain class 37

Slide 38: Controller • Grails Services can be used to encapsulate business logic • Services may be injected into Controllers • “grails create-service” creates a new service in grails-app/services 38

Slide 39: Controller • Example Service class CountryService { def String sayHello(String name) { return "hello ${name}" } } • Used within a controller class GreetingController { CountryService countryService def helloAction = { render(countryService.sayHello(params.name)) } } 39

Slide 40: About Scaffolding... • Use it to get up to speed, have something to show and work on • You will not scaffold your complete web application • Learn from the generated code, tweak it to fit your individual needs 40

Slide 41: Grails Features 41

Slide 42: Auto Reloading • In development mode, Grails synchronizes the current application with the server • Controllers, GSPs, Tag Libraries, Domain Classes, Services, etc. • This is essential for an iterative and incremental development. • Call it “agile” if you like! 42

Slide 43: Spring Integration • You can put additional Spring configuration in the /spring directory and use it to configure your beans • Automatic DI is available even for these beans (not just Services) • Easily integrate existing (Java) functionality that was configured with Spring 43

Slide 44: Hibernate Integration • You can specify your own HBM files for your domain classes. (You can even use your existing Java classes if you like) • Working with legacy database schemas is getting really simple • Still use all benefits like dynamic finder methods 44

Slide 45: Eclipse “Integration” • Grails creates an Eclipse Project file automatically, just run File > Import > Existing Project • You'll have to tweak some file names if you use the development snapshot versions • Be sure to install the Groovy Plugin: groovy.codehaus.org/Eclipse+Plugin 45

Slide 46: AJAX • Grails supports AJAX with different AJAX toolkits, currently Prototype, Dojo and Yahoo • Special AJAX tags can be used for asynchronous calls and form submission <div id="message"></div> <g:remoteLink action="delete" id="1" update="message">Delete Book</g:remoteLink> 46

Slide 47: AJAX • On the server side, Grails supports AJAX via the render() Method, which makes AJAX responses really easy: def time = { render(contentType:'text/xml') { time(new Date()) } } • Render() supports MarkupBuilders for XML, HTML, JSON, OpenRico 47

Slide 48: Job Scheduling • Grails makes using Quartz even easier, just create this (in grails-app/jobs): class MyJob { def cronExpression = "0,15,30,45 * * * * ?" //every 15 seconds def execute(){ println "Running job!" } } 48

Slide 49: Unit & Functional Testing • Both unit and functional testing supported • Functional Testing uses Canoo Webtest • “grails test-app” runs the unit tests • “grails run-webtest” • Generate a webtest with • “grails generate-webtest” 49

Slide 50: Grails Roadmap 50

Slide 51: The Sandbox • New Controllers • Page Flows • Constraints for DB-Schema creation • Laszlo on Grails • Mail / Messaging Integration • Test DataSets • Plugin-System 51

Slide 52: Roadmap • 0.3 • Spring 2 • Web Services Service Classes • M:N Mapping for GORM • 0.4 • DWR Support for Service Classes • Pluggable Persistence Layer 52

Slide 53: Roadmap • 0.5 • XML-RPC for Service Classes • Generation of Domain Model from DB Schema • 0.6 • Scaffolding of User Authentication Code • Grails is user-centric, you define what really happens. Vote in Jira: http://jira.codehaus.org/browse/GRAILS 53

Slide 54: Your Next Steps 54

Slide 55: Learn more • Download, Install, create your first app with the Quickstart Guide http://www.grails.org/Quick+Start • Check out the Tutorials Section http://www.grails.org/Tutorials 55

Slide 56: Learn more • Read & Work through the user guide http://www.grails.org/User+Guide • Get onto the Grails user mailing list http://www.grails.org/Mailing+lists • Remember: Grails is open source... • The more you contribute, the more you get out in terms of learning, jobs, contacts... 56

Slide 57: Watch • Currently two screencasts available • Scaffolding • Directory Structure http://www.grails.org/Grails+Screencasts 57

Slide 58: Listen • Grails Podcast • Weekly Show • Grails News • Grails Features • Interviews • Agile Development http://hansamann.podspot.de/rss 58

Slide 59: Read • Out soon! • By Graeme Rocher, Grails Project Lead • ISBN: 1-59059-758-3 59

Slide 60: Contribute • Be part of the community • Contribute a Tag! grails.org/Contribute+a+Tag • Blog about Grails! Now! • Answer questions on the Grails Users List! • and... 60

Slide 61: Groovy & Grails Shop N e !• Buy your girlfriend one of w those sexy Groovy GStrings • http://tinyurl.com/y3zmos 61

Slide 62: GRAILS RAPID WEB APP DEVELOPMENT MADE EASY Questions? www.grails.org www.svenhaiges.de 62