0
Groovy And GrailsHarshad OakRightrix Solutions
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovy Basics• Scripting / Agile / Dynamic ...Language• Syntax very ...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovy Basics• Open source using a BSD / Apache style licence• Backe...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovy Installation• Download binary• Set GROOVY_HOME• Add GROOVY_HO...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovy with Java• Use groovyc just like javac to produce bytecodefil...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Closures• Closures are reusable blocks of code• One or more program ...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Closures• Can be passed around like a variable• The statements withi...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Dynamic Methods• Adding new methods to an object at runtime• Interce...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovy Features• Language Constructs• List & Maps support• XML Capab...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovlets and GSP• Groovy alternatives for Servlets and JSP• Will wo...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovlets and GSP• Implicit Variables• request ServletRequest• respo...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails• Web Framework inspired by Ruby On Rails• Latest version is 0...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails• Provides several commands to auto generatecommon requirement...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Installation• Extract contents• Set GRAILS_HOME environment v...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Application StructureControllersDomain ClassesViewsNormal J2E...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06GORM• Domain Classes are objects that are mapped tothe database• Use...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Development• Example -Develop a Clothes Manager webapplicatio...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Development - DomainClasses• Create Domain Classes• Cabinet.g...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Development-Controllers• Controllers are responsible for hand...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Development -Views• Controllers delegate to view based on aco...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Development -Deploy• Built in Resin server• Directly run your...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Custom View andController• Grails currently only auto generat...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Services• Services are named in the formatXXService.groovy• D...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Tags• Range of tags for both GSPs and JSPs• No configuration•...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails - Ajax• Can work with Prototype, Yahoo or Dojo• Configure the...
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails• Testing• IDE Integration• Validation
Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Thank You• Further Reading• groovy.codehaus.org• grails.org• Several...
Upcoming SlideShare
Loading in...5
×

Groovy grailstutorial

589

Published on

About Groovy

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

  • Be the first to like this

No Downloads
Views
Total Views
589
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Groovy grailstutorial"

  1. 1. Groovy And GrailsHarshad OakRightrix Solutions
  2. 2. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovy Basics• Scripting / Agile / Dynamic ...Language• Syntax very close to Java• Meant for Java developers.• A powerful high level language for the Java“platform”• Groovy code Compiles to Java bytecode.• You can get productive quickly
  3. 3. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovy Basics• Open source using a BSD / Apache style licence• Backed by JSR 241• groovy.codehaus.org
  4. 4. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovy Installation• Download binary• Set GROOVY_HOME• Add GROOVY_HOME/bin to your PATH• Set JAVA_HOME
  5. 5. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovy with Java• Use groovyc just like javac to produce bytecodefiles• Groovy integrates with the Bean ScriptingFramework, which allows you to embed anyscripting engine into your Java code
  6. 6. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Closures• Closures are reusable blocks of code• One or more program statements enclosed incurly brackets• Closures do not require a class or a methodname
  7. 7. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Closures• Can be passed around like a variable• The statements within a closure are notexecuted until the call() is made• Return is using an explicit return statement orthe value of the last executed statement
  8. 8. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Dynamic Methods• Adding new methods to an object at runtime• Intercept non-existent method calls• Used extensively in Grails• Meta-Object Protocol
  9. 9. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovy Features• Language Constructs• List & Maps support• XML Capabilities• Swing Capabilities
  10. 10. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovlets and GSP• Groovy alternatives for Servlets and JSP• Will work on any J2EE container.• Add JAR files• Tweak web.xml
  11. 11. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Groovlets and GSP• Implicit Variables• request ServletRequest• response ServletResponse -• context ServletContext• application ServletContext• session getSession(false)• out response.getWriter()• sout response.getOutputStream()• html new MarkupBuilder(out)
  12. 12. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails• Web Framework inspired by Ruby On Rails• Latest version is 0.2.1• Coding by convention paradigm• Reduce the need for configuration files andother boilerplate code• File names are important
  13. 13. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails• Provides several commands to auto generatecommon requirements in a web app.• Based on open source technologies like Spring,Hibernate and SiteMesh• Grails hides underlying complexity• Focus is on rapid development and simplicity
  14. 14. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Installation• Extract contents• Set GRAILS_HOME environment variable• Add GRAILS_HOMEbin to the PATH variable• Run the grails command from the commandprompt to check usage
  15. 15. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Application StructureControllersDomain ClassesViewsNormal J2EE webapplication
  16. 16. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06GORM• Domain Classes are objects that are mapped tothe database• Uses Hibernate 3 underneath• Link domain classes using relationships• Provide powerful dynamic methods for CRUD(Create/Read/Update/Delete) operations• An HSQL database comes built-in with Grails
  17. 17. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Development• Example -Develop a Clothes Manager webapplication• Use MySQL database•Setup DB•Setup ApplicationDataSource• Create Domain Classes
  18. 18. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Development - DomainClasses• Create Domain Classes• Cabinet.groovy• Shirt.groovy• Trouser.groovy• Define relationships
  19. 19. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Development-Controllers• Controllers are responsible for handling therequests in the web application• Use grails -generate-all to generate controllersfor our 3 domain classes• Once controller is done processing a request, ithas to delegate to an appropriate view
  20. 20. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Development -Views• Controllers delegate to view based on aconvention mechanism• So list closure in ShirtController will delegate tothe view /grails-app/views/shirt/list.gsp or/grails-app/views/shirt/list.jsp.• Note that you can use JSPs
  21. 21. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Development -Deploy• Built in Resin server• Directly run your application by using the grailsrun-app command• Lets use Tomcat instead• WAR file creation using grails war• Deploy the WAR file just like any other J2EEWAR file
  22. 22. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Custom View andController• Grails currently only auto generates views basedon a domain class• Manually create a new view• Edit web.xml for mapping the new view• Deploy and try out on Tomcat
  23. 23. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Services• Services are named in the formatXXService.groovy• Directory /grails-app/services• Can have Business Logic• You can call these services from withincontrollers
  24. 24. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails Tags• Range of tags for both GSPs and JSPs• No configuration• No updating of TLD descriptors• Edit grails-apptaglibApplicationTagLib.groovyor create a new file XXTagLib.groovy
  25. 25. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails - Ajax• Can work with Prototype, Yahoo or Dojo• Configure the library and then just use the grailstags• Use render method to send text, markup, JSONor OpenRico responses
  26. 26. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Grails• Testing• IDE Integration• Validation
  27. 27. Harshad Oak - Groovy and Grails Tutorial - 17th Aug 06Thank You• Further Reading• groovy.codehaus.org• grails.org• Several books in the works• Groovy in Action (Manning)• Groovy Programming: An Introduction for JavaDevelopers (Morgan Kaufmann)Harshad Oak - harshad@rightrix.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×