SlideShare uma empresa Scribd logo
1 de 37
Agile Web Development with
Groovy and Grails

 Carol McDonald, Java Architect
Objective



Overview of the
    Grails
 Web Platform
                  2
Groovy Overview



                  3
What is Groovy?
• A dynamic language written for the JVM
  > Generates byte code
• Java like syntax
  > Easy learning curve for Java developers
• Seamless integration with Java
  > A Groovy object is a Java Object
  > Groovy application can create Java objects
  > Java objects can create Groovy objects




                                                 4
A Valid Java Program
import java.util.*;
public class Erase {
    private List<String> filterLongerThan(List<String> strings, int length) {
         List<String> result = new ArrayList<String>();
        for (String n: strings)
             if (n.length() <= length)
                  result.add(n);
        return (result);
    }
    public static void main(String[] args) {
         List<String> names = new ArrayList<String>();
        names.add("Ted");
        names.add("Fred");
        names.add("Jed");
        names.add("Ned");
        System.out.println(names);
        Erase e = new Erase();
        List shortNames = e.filterLongerThan(names, 3);
        System.out.println(shortNames);
    }
}                                                                               5
A Valid Groovy Program
import java.util.*;
public class Erase {
    private List<String> filterLongerThan(List<String> strings, int length) {
         List<String> result = new ArrayList<String>();
        for (String n: strings)
             if (n.length() <= length)
                  result.add(n);
        return (result);
    }
    public static void main(String[] args) {
         List<String> names = new ArrayList<String>();
        names.add("Ted");
        names.add("Fred");
        names.add("Jed");
        names.add("Ned");
        System.out.println(names);
        Erase e = new Erase();
        List shortNames = e.filterLongerThan(names, 3);
        System.out.println(shortNames);
    }
}                                                                               6
The Groovy Way

def names = ["Ted", "Fred", "Jed", "Ned"]

println names

def shortNames = names.findAll{
    it.size() <= 3
}

print shortNames



                                            7
Grails Overview



                  8
What is Grails?
• An Open Source Groovy MVC framework for
  web applications
• Principles
  > CoC – Convention over configuration
  > DRY – Don't repeat yourself
• Similar to RoR but with tighter integration to the
 Java platform




                                                       9
Why Grails?
• ORM layer can be overly difficult to master and
 get right
  > A return to POJO and annotations in JPA but still lots
    of stuff to learn
• Numerous layers and configuration files lead to
 chaos
  > Adoption of frameworks a good thing, but too often
    lead to configuration file hell
• Ugly JSPs with scriptlets and complexity of JSP
  custom tags
• Grails addresses these without compromising
  their benefits
                                                             10
Grails Technology Stack




                          11
How To Get Started
• Download Grails
  > http://grails.org
• Configure Netbeans 6.5




• Download Groovy
  > http://groovy.codehaus.org
• Set GROOVY_HOME, GRAILS_HOME          For command
• Add bin to your PATH
                                        line
  > $GROOVY_HOME/bin:$GRAILS_HOME/bin
                                                      12
Using Grails


               13
grails create­app
• Will be prompted for the name of the application


                                       IDE runs the
                                       "grails create-app"
                                       command



• Generate a directory structure for
  > Grails source
  > Additional libraries
  > Configurations
  > web-app
                                                         14
Grails Directory
Structure

Application
  name



                   Grail source


Additional
  JARs

    Web
  application

                                  15
Netbeans Grails
Project Structure

Project name




                    Grail source


Additional
  JARs

    Web
  application

                                   16
Configure for MySQL
• copy the mysql-connector-java-5.1.6-bin.jar to the lib directory
• Edit DataSource.groovy

dataSource {
  pooled = true
  driverClassName = "com.mysql.jdbc.Driver"
  username = "root"
  password = ""
  dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
}
environments {
  development {
     dataSource {
       dbCreate = "update" // one of 'create', 'create-drop','update'
       url = "jdbc:mysql://localhost/petcatalog"
     }
  }



                                                                        17
MVC and Grails




                 • Models, or domain
                  classes, represent the
                  problem domain



                                           18
grails create­domain­class




• The Model is your application's persistent
 business domain objects.
                                               19
add the domain class attributes
class Item {
  Long id
  String name
  String description
  String imageurl
  String imagethumburl
  BigDecimal price

}
    Groovy with Grails dynamically generates getters and setters
    and the dynamic methods Item.save(), Item.delete(), Item.list(),
     Item.get() to retrieve/update data from/to the db table.

                                                                       20
Persistence Methods
• GORM automatically provides persistence
  methods to your object
  > save(), get(), delete()
• Automatically generates addTo*() for object
  relationships
  > Where * is the name of the property

def item = new Item(name:'Fred')
def order = 
   new Order(orderDate: new Date(), item: 'PSP')
item.addToOrders(order)
item.save()


                                                   21
Queries
• Dynamically generated queries
  > list, findBy
• Manual queries (not discussed here)
  > HibernateQL
• Examples
  > Item.list()
  > Item.findByName('nice cat')




                                        22
grails domain class
  Item                                 Address

 String name          1           M   String street
 String description
                                      String zip
 Address address
                                      static hasMany =
                                      [item:Item]




• Define relation between objects with attributes
  > hasMany, belongsTo
  > static hasMany = [ item: Item ]
                                      Groovy hashmap

                                                         23
Scaffolding
• Generates CRUD actions and views for the
  corresponding domain class
• Dynamic:
  > Enable the scaffold property in the controller class
     def scaffold = true
• Static
  > grails generate­all
  > Generates a controller and views for a 
    domain class
• Useful to get up and running quickly



                                                           24
Scaffolding
• Generates a controller and views for the domain
 class




                                                    25
MVC and Grails


                 • Controllers control
                  request flow, interact
                  with models, and
                  delegate to views.




                                           26
grails create­controller
  • Controller made up of action methods
    > Grails routes requests to the action corresponding to
      URL mapping
    > Default action is index

    class ItemController {    
       def index = { redirect(action:list,params:params) }
       def list = {
                                    http://host/catalog/item/list
          if(!params.max) params.max = 10
             [ itemList: Item.list( params ) ]
       }
       def show = {...

Actions
                                                              27
URL Mappings
• Default mapping from URL to action method
         http://host/catalog/item/list

              Application   Controller Action

• Defined in
  > grails­app/conf/UrlMappings.groovy

  static mappings = {
        "/$controller/$action?/$id?"




                                                28
grails controller

class ItemController {    
   def index = { redirect(action:list,params:params) }
   def list = {
      if(!params.max) params.max = 10
         [ itemInstanceList: Item.list( params ) ]
   }
   def show = {...
                                  returns an ArrayList of item objects
                                  retrieved from the item database table
      itemInstanceList variable is made
      available to the view


                                                                      29
MVC and Grails




   • Views are defined in Groovy
     Server Pages (GSP) and
     render the model
                                   30
grails view
 • actions usually render a Groovy Server Page in the
   views directory corresponding to the name of the
   controller and action. list.gsp
<html> 
<table>      g:each Groovy Tag loops through each object in the
  <tbody>   itemInstanceList variable
      <g:each in="${itemInstanceList}" status="i" 
var="itemInstance">
          
              <td>${fieldValue(bean:itemInstance, 
field:'price')}</td>

          </tr>             displays the value of the item 's price attribute
      </g:each>
  </tbody>
 </table>                                                                  31
grails run­app
• Will start the embedded web server and run the
  application
• Defaults to
  > http://localhost:8080/<app_name>




                                                   32
Summary
• Groovy is a powerful dynamic language for the
  JVM
• Grails is a full featured web platform




                                                  33
http://weblogs.java.net/blog/caroljmcdonald
 /




                                              34
Acknowldegement
• Thanks to Guilaume Laforge of G2One for
 allowing me to use and adapt some of his slides




                                                   35
●




    Carol McDonald
    Java Architect

     Tech Days 2009




                      36
Lots of Books and Online Tutorials




                                     37

Mais conteúdo relacionado

Mais procurados

Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneAndres Almiray
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
Restful App Engine
Restful App EngineRestful App Engine
Restful App EngineRyan Morlok
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Scott Leberknight
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Hermann Hueck
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 
Realm or: How I learned to stop worrying and love my app database
Realm or: How I learned to stop worrying and love my app databaseRealm or: How I learned to stop worrying and love my app database
Realm or: How I learned to stop worrying and love my app databaseSergi Martínez
 
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsNeo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsMark Needham
 
Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch? Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch? DataWorks Summit
 
Grails: a quick tutorial (1)
Grails: a quick tutorial (1)Grails: a quick tutorial (1)
Grails: a quick tutorial (1)Davide Rossi
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaScott Hernandez
 
Whats New for WPF in .NET 4.5
Whats New for WPF in .NET 4.5Whats New for WPF in .NET 4.5
Whats New for WPF in .NET 4.5Rainer Stropek
 
Writing Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingWriting Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingToni Cebrián
 

Mais procurados (20)

Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
Restful App Engine
Restful App EngineRestful App Engine
Restful App Engine
 
GORM
GORMGORM
GORM
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
Green dao
Green daoGreen dao
Green dao
 
Why realm?
Why realm?Why realm?
Why realm?
 
Green dao
Green daoGreen dao
Green dao
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
Presto in Treasure Data
Presto in Treasure DataPresto in Treasure Data
Presto in Treasure Data
 
Realm or: How I learned to stop worrying and love my app database
Realm or: How I learned to stop worrying and love my app databaseRealm or: How I learned to stop worrying and love my app database
Realm or: How I learned to stop worrying and love my app database
 
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsNeo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
 
Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch? Should I Use Scalding or Scoobi or Scrunch?
Should I Use Scalding or Scoobi or Scrunch?
 
Grails: a quick tutorial (1)
Grails: a quick tutorial (1)Grails: a quick tutorial (1)
Grails: a quick tutorial (1)
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with Morphia
 
Gorm
GormGorm
Gorm
 
Whats New for WPF in .NET 4.5
Whats New for WPF in .NET 4.5Whats New for WPF in .NET 4.5
Whats New for WPF in .NET 4.5
 
Writing Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingWriting Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using Scalding
 

Destaque

Comparing JVM Web Frameworks - February 2014
Comparing JVM Web Frameworks - February 2014Comparing JVM Web Frameworks - February 2014
Comparing JVM Web Frameworks - February 2014Matt Raible
 
The Near Future of CSS
The Near Future of CSSThe Near Future of CSS
The Near Future of CSSRachel Andrew
 
Classroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsClassroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsShelly Sanchez Terrell
 
How to Battle Bad Reviews
How to Battle Bad ReviewsHow to Battle Bad Reviews
How to Battle Bad ReviewsGlassdoor
 
Activism x Technology
Activism x TechnologyActivism x Technology
Activism x TechnologyWebVisions
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back KidEthos3
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaChris Lema
 

Destaque (7)

Comparing JVM Web Frameworks - February 2014
Comparing JVM Web Frameworks - February 2014Comparing JVM Web Frameworks - February 2014
Comparing JVM Web Frameworks - February 2014
 
The Near Future of CSS
The Near Future of CSSThe Near Future of CSS
The Near Future of CSS
 
Classroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsClassroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and Adolescents
 
How to Battle Bad Reviews
How to Battle Bad ReviewsHow to Battle Bad Reviews
How to Battle Bad Reviews
 
Activism x Technology
Activism x TechnologyActivism x Technology
Activism x Technology
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back Kid
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris Lema
 

Semelhante a Groovygrailsnetbeans 12517452668498-phpapp03

Agile web development Groovy Grails with Netbeans
Agile web development Groovy Grails with NetbeansAgile web development Groovy Grails with Netbeans
Agile web development Groovy Grails with NetbeansCarol McDonald
 
Fast web development using groovy on grails
Fast web development using groovy on grailsFast web development using groovy on grails
Fast web development using groovy on grailsAnshuman Biswal
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...Fons Sonnemans
 
Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)Ontico
 
Grails Integration Strategies
Grails Integration StrategiesGrails Integration Strategies
Grails Integration Strategiesdaveklein
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksMike Hugo
 
Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Corneil du Plessis
 
Groovy and Grails intro
Groovy and Grails introGroovy and Grails intro
Groovy and Grails introMiguel Pastor
 
Groovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsGroovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsIndicThreads
 
Android UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesAndroid UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesEdgar Gonzalez
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesMarakana Inc.
 
Groovy Grails Gr8Ladies Women Techmakers: Minneapolis
Groovy Grails Gr8Ladies Women Techmakers: MinneapolisGroovy Grails Gr8Ladies Women Techmakers: Minneapolis
Groovy Grails Gr8Ladies Women Techmakers: MinneapolisJenn Strater
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applicationsrohitnayak
 
Porting legacy apps to Griffon
Porting legacy apps to GriffonPorting legacy apps to Griffon
Porting legacy apps to GriffonJames Williams
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)lennartkats
 

Semelhante a Groovygrailsnetbeans 12517452668498-phpapp03 (20)

Agile web development Groovy Grails with Netbeans
Agile web development Groovy Grails with NetbeansAgile web development Groovy Grails with Netbeans
Agile web development Groovy Grails with Netbeans
 
Os Davis
Os DavisOs Davis
Os Davis
 
Fast web development using groovy on grails
Fast web development using groovy on grailsFast web development using groovy on grails
Fast web development using groovy on grails
 
Introduction To Grails
Introduction To GrailsIntroduction To Grails
Introduction To Grails
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
 
Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)
 
Everything as a code
Everything as a codeEverything as a code
Everything as a code
 
Gradle
GradleGradle
Gradle
 
Grails 101
Grails 101Grails 101
Grails 101
 
Grails Integration Strategies
Grails Integration StrategiesGrails Integration Strategies
Grails Integration Strategies
 
Building Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And Tricks
 
Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!
 
Groovy and Grails intro
Groovy and Grails introGroovy and Grails intro
Groovy and Grails intro
 
Groovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsGroovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applications
 
Android UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and TechniquesAndroid UI Development: Tips, Tricks, and Techniques
Android UI Development: Tips, Tricks, and Techniques
 
Android UI Tips, Tricks and Techniques
Android UI Tips, Tricks and TechniquesAndroid UI Tips, Tricks and Techniques
Android UI Tips, Tricks and Techniques
 
Groovy Grails Gr8Ladies Women Techmakers: Minneapolis
Groovy Grails Gr8Ladies Women Techmakers: MinneapolisGroovy Grails Gr8Ladies Women Techmakers: Minneapolis
Groovy Grails Gr8Ladies Women Techmakers: Minneapolis
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
 
Porting legacy apps to Griffon
Porting legacy apps to GriffonPorting legacy apps to Griffon
Porting legacy apps to Griffon
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
 

Último

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Último (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Groovygrailsnetbeans 12517452668498-phpapp03

  • 1. Agile Web Development with Groovy and Grails Carol McDonald, Java Architect
  • 2. Objective Overview of the Grails Web Platform 2
  • 4. What is Groovy? • A dynamic language written for the JVM > Generates byte code • Java like syntax > Easy learning curve for Java developers • Seamless integration with Java > A Groovy object is a Java Object > Groovy application can create Java objects > Java objects can create Groovy objects 4
  • 5. A Valid Java Program import java.util.*; public class Erase { private List<String> filterLongerThan(List<String> strings, int length) { List<String> result = new ArrayList<String>(); for (String n: strings) if (n.length() <= length) result.add(n); return (result); } public static void main(String[] args) { List<String> names = new ArrayList<String>(); names.add("Ted"); names.add("Fred"); names.add("Jed"); names.add("Ned"); System.out.println(names); Erase e = new Erase(); List shortNames = e.filterLongerThan(names, 3); System.out.println(shortNames); } } 5
  • 6. A Valid Groovy Program import java.util.*; public class Erase { private List<String> filterLongerThan(List<String> strings, int length) { List<String> result = new ArrayList<String>(); for (String n: strings) if (n.length() <= length) result.add(n); return (result); } public static void main(String[] args) { List<String> names = new ArrayList<String>(); names.add("Ted"); names.add("Fred"); names.add("Jed"); names.add("Ned"); System.out.println(names); Erase e = new Erase(); List shortNames = e.filterLongerThan(names, 3); System.out.println(shortNames); } } 6
  • 7. The Groovy Way def names = ["Ted", "Fred", "Jed", "Ned"] println names def shortNames = names.findAll{ it.size() <= 3 } print shortNames 7
  • 9. What is Grails? • An Open Source Groovy MVC framework for web applications • Principles > CoC – Convention over configuration > DRY – Don't repeat yourself • Similar to RoR but with tighter integration to the Java platform 9
  • 10. Why Grails? • ORM layer can be overly difficult to master and get right > A return to POJO and annotations in JPA but still lots of stuff to learn • Numerous layers and configuration files lead to chaos > Adoption of frameworks a good thing, but too often lead to configuration file hell • Ugly JSPs with scriptlets and complexity of JSP custom tags • Grails addresses these without compromising their benefits 10
  • 12. How To Get Started • Download Grails > http://grails.org • Configure Netbeans 6.5 • Download Groovy > http://groovy.codehaus.org • Set GROOVY_HOME, GRAILS_HOME For command • Add bin to your PATH line > $GROOVY_HOME/bin:$GRAILS_HOME/bin 12
  • 14. grails create­app • Will be prompted for the name of the application IDE runs the "grails create-app" command • Generate a directory structure for > Grails source > Additional libraries > Configurations > web-app 14
  • 15. Grails Directory Structure Application name Grail source Additional JARs Web application 15
  • 16. Netbeans Grails Project Structure Project name Grail source Additional JARs Web application 16
  • 17. Configure for MySQL • copy the mysql-connector-java-5.1.6-bin.jar to the lib directory • Edit DataSource.groovy dataSource { pooled = true driverClassName = "com.mysql.jdbc.Driver" username = "root" password = "" dialect = "org.hibernate.dialect.MySQL5InnoDBDialect" } environments { development { dataSource { dbCreate = "update" // one of 'create', 'create-drop','update' url = "jdbc:mysql://localhost/petcatalog" } } 17
  • 18. MVC and Grails • Models, or domain classes, represent the problem domain 18
  • 19. grails create­domain­class • The Model is your application's persistent business domain objects. 19
  • 20. add the domain class attributes class Item { Long id String name String description String imageurl String imagethumburl BigDecimal price } Groovy with Grails dynamically generates getters and setters and the dynamic methods Item.save(), Item.delete(), Item.list(), Item.get() to retrieve/update data from/to the db table. 20
  • 21. Persistence Methods • GORM automatically provides persistence methods to your object > save(), get(), delete() • Automatically generates addTo*() for object relationships > Where * is the name of the property def item = new Item(name:'Fred') def order =  new Order(orderDate: new Date(), item: 'PSP') item.addToOrders(order) item.save() 21
  • 22. Queries • Dynamically generated queries > list, findBy • Manual queries (not discussed here) > HibernateQL • Examples > Item.list() > Item.findByName('nice cat') 22
  • 23. grails domain class Item Address String name 1 M String street String description String zip Address address static hasMany = [item:Item] • Define relation between objects with attributes > hasMany, belongsTo > static hasMany = [ item: Item ] Groovy hashmap 23
  • 24. Scaffolding • Generates CRUD actions and views for the corresponding domain class • Dynamic: > Enable the scaffold property in the controller class def scaffold = true • Static > grails generate­all > Generates a controller and views for a  domain class • Useful to get up and running quickly 24
  • 25. Scaffolding • Generates a controller and views for the domain class 25
  • 26. MVC and Grails • Controllers control request flow, interact with models, and delegate to views. 26
  • 27. grails create­controller • Controller made up of action methods > Grails routes requests to the action corresponding to URL mapping > Default action is index class ItemController {     def index = { redirect(action:list,params:params) } def list = { http://host/catalog/item/list if(!params.max) params.max = 10 [ itemList: Item.list( params ) ] } def show = {... Actions 27
  • 28. URL Mappings • Default mapping from URL to action method http://host/catalog/item/list Application Controller Action • Defined in > grails­app/conf/UrlMappings.groovy static mappings = {       "/$controller/$action?/$id?" 28
  • 29. grails controller class ItemController {     def index = { redirect(action:list,params:params) } def list = { if(!params.max) params.max = 10 [ itemInstanceList: Item.list( params ) ] } def show = {... returns an ArrayList of item objects retrieved from the item database table itemInstanceList variable is made available to the view 29
  • 30. MVC and Grails • Views are defined in Groovy Server Pages (GSP) and render the model 30
  • 31. grails view • actions usually render a Groovy Server Page in the views directory corresponding to the name of the controller and action. list.gsp <html>  <table> g:each Groovy Tag loops through each object in the   <tbody> itemInstanceList variable       <g:each in="${itemInstanceList}" status="i"  var="itemInstance">                          <td>${fieldValue(bean:itemInstance,  field:'price')}</td>           </tr> displays the value of the item 's price attribute       </g:each>   </tbody>  </table> 31
  • 32. grails run­app • Will start the embedded web server and run the application • Defaults to > http://localhost:8080/<app_name> 32
  • 33. Summary • Groovy is a powerful dynamic language for the JVM • Grails is a full featured web platform 33
  • 35. Acknowldegement • Thanks to Guilaume Laforge of G2One for allowing me to use and adapt some of his slides 35
  • 36. Carol McDonald Java Architect Tech Days 2009 36
  • 37. Lots of Books and Online Tutorials 37