Grails - Rapid Web Application Development for the Java Platform



Similar documents
Agile Development with Groovy and Grails. Christopher M. Judd. President/Consultant Judd Solutions, LLC

Rapid Application Development. and Application Generation Tools. Walter Knesel

Table of contents. Reverse-engineers a database to Grails domain classes.

Grails 1.1. Web Application. Development. Reclaiming Productivity for Faster. Java Web Development. Jon Dickinson PUBLISHING J MUMBAI BIRMINGHAM

Dynamic website development using the Grails Platform. Joshua Davis Senior Architect Cognizant Technology Solutions

Intruduction to Groovy & Grails programming languages beyond Java

Clustering a Grails Application for Scalability and Availability

Grails: Accelerating J2EE Application Development

Database Migration Plugin - Reference Documentation

Install guide for Websphere 7.0

FreeSB Installation Guide 1. Introduction Purpose

SpagoBI exo Tomcat Installation Manual

Enterprise Application Development In Java with AJAX and ORM

GlassFish v3. Building an ex tensible modular Java EE application server. Jerome Dochez and Ludovic Champenois Sun Microsystems, Inc.

Web Development with Grails

A Sample OFBiz application implementing remote access via RMI and SOAP Table of contents

WEBLOGIC ADMINISTRATION

Witango Application Server 6. Installation Guide for OS X

Sonatype CLM Enforcement Points - Continuous Integration (CI) Sonatype CLM Enforcement Points - Continuous Integration (CI)

Drupal CMS for marketing sites

Apache Jakarta Tomcat

MagDiSoft Web Solutions Office No. 102, Bramha Majestic, NIBM Road Kondhwa, Pune Tel: /

OpenReports: Users Guide

Sonatype CLM for Maven. Sonatype CLM for Maven

Grails 1.1 Web Application Development

Build management & Continuous integration. with Maven & Hudson

CHRIS RICHARDSON, CONSULTANT FOCUS

Infinitel HotSpotWeb User Manual

In this chapter, we lay the foundation for all our further discussions. We start

Automating Testing and Configuration Data Migration in OTM/GTM Projects using Open Source Tools By Rakesh Raveendran Oracle Consulting

Using the LiveCycle Data Services ES2 Sample Application Version 3.1

Force.com Migration Tool Guide

Ruby on Rails is a web application framework written in Ruby, a dynamically typed programming language The amazing productivity claims of Rails is

WebLogic Server: Installation and Configuration

Glassfish, JAVA EE, Servlets, JSP, EJB

Web Frameworks. web development done right. Course of Web Technologies A.A. 2010/2011 Valerio Maggio, PhD Student Prof.

BIRT Application and BIRT Report Deployment Functional Specification

Kony MobileFabric. Sync Windows Installation Manual - WebSphere. On-Premises. Release 6.5. Document Relevance and Accuracy

Web Frameworks and WebWork

Migrating Applications From IBM WebSphere to Apache Tomcat

Web-JISIS Reference Manual

Model-View-Controller. and. Struts 2

Ruby on Rails in GlassFish Sun Microsystems

Web Applications and Struts 2

Getting Started using the SQuirreL SQL Client

Grails in Action MANNING. (74 w. long.) GLEN SMITH PETER LEDBROOK. Greenwich

Secure Test Data Management with ORACLE Data Masking

NGASI AppServer Manager SaaS/ASP Hosting Automation for Cloud Computing Administrator and User Guide

Creating Web Services Applications with IntelliJ IDEA

Builder User Guide. Version Visual Rules Suite - Builder. Bosch Software Innovations

Agile Best Practices and Patterns for Success on an Agile Software development project.

Building and Using Web Services With JDeveloper 11g

Installation Guide for contineo

Enhanced Connector Applications SupportPac VP01 for IBM WebSphere Business Events 3.0.0

Developing Web Services with Eclipse and Open Source. Claire Rogers Developer Resources and Partner Enablement, HP February, 2004

Crystal Reports for Eclipse

Builder User Guide. Version 5.4. Visual Rules Suite - Builder. Bosch Software Innovations

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

Install BA Server with Your Own BA Repository

<Insert Picture Here> GlassFish v3 - A Taste of a Next Generation Application Server

JobScheduler and Script Languages

CUT YOUR GRAILS APPLICATION TO PIECES

YouTrack MPS case study

CrownPeak Java Web Hosting. Version 0.20

Application Notes for Packaging and Deploying Avaya Communications Process Manager Sample SDK Web Application on a JBoss Application Server Issue 1.

Web Applications. For live Java training, please see training courses at

Using Actian PSQL as a Data Store with VMware vfabric SQLFire. Actian PSQL White Paper May 2013

EVALUATION ONLY. WA2088 WebSphere Application Server 8.5 Administration on Windows. Student Labs. Web Age Solutions Inc.

Overview of Web Services API

WEBAPP PATTERN FOR APACHE TOMCAT - USER GUIDE

Braindumps.C questions

Getting Started with Telerik Data Access. Contents

Server Setup and Configuration

WebSphere v5 Administration, Network Deployment Edition

3. Installation and Configuration. 3.1 Java Development Kit (JDK)

<Insert Picture Here> What's New in NetBeans IDE 7.2

a) Install the SDK into a directory of your choice (/opt/java/jdk1.5.0_11, /opt/java/jdk1.6.0_02, or YOUR_JAVA_HOME_DIR)

XMLVend Protocol Message Validation Suite

How To Use The Listerv Maestro With A Different Database On A Different System (Oracle) On A New Computer (Orora)

JobScheduler Web Services Executing JobScheduler commands

Server-side OSGi with Apache Sling. Felix Meschberger Day Management AG 124

IBM TRIRIGA Anywhere Version 10 Release 4. Installing a development environment

BEST WEB PROGRAMMING LANGUAGES TO LEARN ON YOUR OWN TIME

Test Automation Integration with Test Management QAComplete

SDK Code Examples Version 2.4.2

Learning GlassFish for Tomcat Users

IUCLID 5 Guidance and Support

Palo Open Source BI Suite

Security Testing of Java web applications Using Static Bytecode Analysis of Deployed Applications

JBoss Portlet Container. User Guide. Release 2.0

Software project management. and. Maven

Alteryx Predictive Analytics for Oracle R

Web Development Frameworks

Informatics for Integrating Biology & the Bedside. i2b2 Workbench Developer s Guide. Document Version: 1.0 i2b2 Software Release: 1.3.

Instant Chime for IBM Sametime Installation Guide for Apache Tomcat and Microsoft SQL

Java in Web 2.0. Alexis Roos Principal Field Technologist, CTO Office OEM SW Sales Sun Microsystems, Inc.

IBM InfoSphere MDM Server v9.0. Version: Demo. Page <<1/11>>

DTS Web Developers Guide

Nick Ashley TOOLS. The following table lists some additional and possibly more unusual tools used in this paper.

ZeroTurnaround License Server User Manual 1.4.0

Transcription:

Grails - Rapid Web Application Development for the Java Platform Mischa Kölliker Guido Schmutz Zürich, 24.06.2008 Basel Baden Bern Lausanne Zurich Düsseldorf Frankfurt/M. Freiburg i. Br. Hamburg Munich Stuttgart Vienna

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 2 2008

What is Grails? Grails is to Groovy what Ruby on Rails is to Ruby aims to bring the "coding by convention" paradigm to Groovy open-source web application framework leverages the Groovy language and complements Java Web development Grails can be used as a standalone development environment that hides all configuration details or integrate your Java business logic Grails aims to make development as simple as possible Grails - Rapid Web Application Development for the Java Platform 3 2008

How Grails stacks up Grails Java EE Spring Hibernate Sitemesh Quartz Groovy Java Language Java Development Kit (JDK) Java Virtual Machine Grails - Rapid Web Application Development for the Java Platform 4 2008

How Grails stacks up Hibernate The de facto standard for ORM in the Java world Spring The hugely popular open source IoC container and wrapper framework for Java Quartz An enterprise-ready, job-scheduling framework allowing flexibility and durable execution of scheduled tasks SiteMesh A robust and stable layout-rendering framework Grails - Rapid Web Application Development for the Java Platform 5 2008

Getting started with Grails Installation in 5 steps 1. download from http://www.grails.org 2. extract zip 3. Set GRAILS_HOME variable 4. Add $GRAILS_HOME\bin to PATH variable 5. run "grails help" Grails - Rapid Web Application Development for the Java Platform 6 2008

Command Line Apache Ant bundled with Grails Many useful targets available: create-* (for creating Grails artifacts) generate-controller generate-views run-app test-app run-webtest help You will never see an Ant build.xml Everything is written as "Gant" script Grails - Rapid Web Application Development for the Java Platform 7 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 8 2008

1) Creating the initial Application C:\temp>grails create-app wineshopdemo Make sure you are in a clean directory The name will be used for the URL the WAR file that gets generate... Convention over configuration Can be overwritten in application.properties file Grails - Rapid Web Application Development for the Java Platform 9 2008

2) Exploring the Directory Structure C:\temp>cd wineshopdemo Grails uses a standard directory structure like Maven, Rails or AppFuse Models, Views, Controllers all of the interesting bits of the application Custom JARS such as DB drivers (WEB-INF/lib) Custom Groovy Scripts Java source files to be compiled (WEB-INF/classes) Unit and integration tests GSPs, CSS, JavaScript and other traditional web files Grails - Rapid Web Application Development for the Java Platform 10 2008

3) Creating a Domain Class C:\temp\wineshopDemo>grails create-domain-class Customer Results in two files Customer.groovy in grails-app/domain class Customer { } CustomerTests.groovy in test/integration class CustomerTests extends GroovyTestCase { void testsomething() { } } Every file in grails-app/domain gets persisted to a database automatically Grails - Rapid Web Application Development for the Java Platform 11 2008

4) Adding Fields to the Domain Class class Customer { String title String firstname String lastname } String tostring() { return "$firstname $lastname" } The domain classes in Grails are GroovyBeans, plain and simple POGO (plain old groovy object) They get more than just automatic getters and setters instance methods customer.save() and customer.delete() static methods such as Customer.get() and Customer.list() Additional fields like id and version Other methods that don't exist like Customer.findByFirstName("Paul") Grails - Rapid Web Application Development for the Java Platform 12 2008

5) Create the Controller and enable scaffolding C:\temp\wineshopDemo>grails create-controller Customer will create a new controller in the grails-app/controllers directory called CustomerController.groovy Scaffolding allows to auto-generate a whole application for a given domain class including The necessary views Controller actions for create/read/update/delete (CRUD) operations Enable scaffolding via the scaffold property class CustomerController { class CustomerController { } def index = { } } def scaffold = true Grails - Rapid Web Application Development for the Java Platform 13 2008

6) Configuration Changing Database Grails allows developing without any additional configuration Grails ships with an embedded container and in-memory HSQLDB to set-up a real database you need to change the defaults and copy the JDBC driver the lib folder datasource { pooled = false driverclassname = "oracle.jdbc.oracledriver" username = "winedemo" password = "winedemo" }... // environment specific settings environments { development { datasource { dbcreate = "update" url = "jdbc:oracle:thin:@localhost:1521:xe" }... Grails - Rapid Web Application Development for the Java Platform 14 2008

7) Starting the Application C:\temp\wineshopDemo>grails run-app Launches the embedded version of Jetty on the default port 8080 to use another port, add server.port property C:\temp\wineshopDemo>grails run-app Dserver.port=8092 After Jetty starts, Grails scans the grails-app/domain folder and creates the necessary tables (depending on configuration) Grails - Rapid Web Application Development for the Java Platform 15 2008

8) Using the application Grails - Rapid Web Application Development for the Java Platform 16 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 17 2008

WineshopDemo Domain Model class Class Model Account - username: String - password: String - active: Boolean +user 0..1 1 Customer - title: String - firstname: String - lastname: String - dateofbirth: java.util.date - phonenumbe r: String - email: String - homepageurl: String +customers 0..* +rating 0..1 Rating - code: String - name: String +customer 1 1..* +addresses {ordered} Address - category: String - street: String - zipcode: String - city: String + fmtpostaladdress() : String +country Country - code: String - name: String Grails - Rapid Web Application Development for the Java Platform 18 2008

Changing the Field Order and Validating the Data With a static constraints block you can control the field order add validation to the fields class Customer {... static constraints = { title(nullable:false, inlist:["herr","frau"]) firstname(nullable:true) lastname(nullable:true) phonenumber(nullable:true) email(nullable:true, email:true) homepageurl(nullable:true, url:true) dateofbirth(nullable:true) } order Methods such as customer.save() validate the object before saving it Grails - Rapid Web Application Development for the Java Platform 19 2008

Validating the Data: Standard validations nullable Ensures the property value cannot be null blank Prevents empty fields email Checks for well-formed email addresses inlist Displays a combo-box unique Prevents duplicate values in the database min, max Minimum, maximum value for a numeric field minsize, maxsize Minimum, maximum length for a text field matches Applies a regular expression against a string value validator Set to a closure or block to use as a custom validation Grails - Rapid Web Application Development for the Java Platform 20 2008

class Class Model Managing Relationships Account - username: String - password: String - active: Boolean +user 0..1 1 Customer - title: String - firstname: String - lastname: String - dateofbirth: java.util.date - phonenumbe r: String - email: String - homepageurl: String +customers 0..* Rating +rating - code: String 0..1 - name: String class Customer {... // one-to-one Account account // many-to-one static belongsto = [rating:rating] +customer 1 Address - category: String - street: String - zipcode: String - city: String 1..* +addresses {ordered} + fmtpostaladdress() : String +country Country - code: String - name: String // one-to-many static hasmany = [addresses:address] class Address {... static belongsto = [customer:customer, country:country] class Rating {... static hasmany = [customers:customer] Grails - Rapid Web Application Development for the Java Platform 21 2008

Custom ORM mappings Table name class Customer {... static mapping = { table 'customer_t' } Column Name class Customer {... static mapping = { table 'customer_t' phonenumber column:'phone_number' } Grails - Rapid Web Application Development for the Java Platform 22 2008

Querying with GORM List all instances or retrieve by id def list = Customer.list(sort: lastname ) def cust = Customer.get(1) class Customer { String title String firstname String lastname Date dateofbirth String phonenumber String email String homepageurl GORM supports the concept of dynamic finders looks like a static method invocation, but the methods don't actually exist def results = Customer.findByFirstName("Andrea") results = Customer.findByFirstNameLike("A%") results = Customer.findByDateOfBirthBetween(fromDate, todate) results = Customer.findAllByEmailIsNull() results = Customer.findByFirstNameIlikeAndDateOfBirthLessThan("a%", new Date()) Hibernate Query Language (HQL) def results = Customer.findAll("from Customer as c where c.firstname like 'G%'") Grails - Rapid Web Application Development for the Java Platform 23 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Overview Controllers View / GSP TagLibs RSS WebServices Plugins Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 24 2008

Controllers and views Grails - Rapid Web Application Development for the Java Platform 25 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Overview Controllers View / GSP TagLibs RSS WebServices Plugins Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 26 2008

Controllers Every domain has it's Controller Controllers consist mainly of a set o action methods (Closures) Lots of implicit objects and methods are injected at runtime. To explore them, start here: org.codehaus.groovy.grails.plugins.web.controllersgrailsplugin org.codehaus.groovy.grails.web.metaclass.renderdynamicmethod Action methods return a model, which is used by the view The model is normally a map If no model is returned, the Controller itself acts as a model The name of the action is used to find a view with the same name Can be overridden Grails - Rapid Web Application Development for the Java Platform 27 2008

Controllers: Output formats Grails - Rapid Web Application Development for the Java Platform 28 2008

Scopes injected to Controllers servletcontext, session, request as usual params a mutual map of request parameters flash a scope living in this and the next request (across redirect) Scope objects are dynamically injected into controllers Controllers itself are prototype-scoped, i.e. live only during one request (and thus are thread safe) Grails - Rapid Web Application Development for the Java Platform 29 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Overview Controllers View / GSP TagLibs RSS WebServices Plugins Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 30 2008

The View: GSP Groovy Server Pages Nearly the same as JSP, but Support Groovy as content of EL expressions More lightweight no compilation Fewer options Templating like Facelets Support Groovy tag libraries Grails - Rapid Web Application Development for the Java Platform 31 2008

Layouting Grails - Rapid Web Application Development for the Java Platform 32 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Overview Controllers View / GSP TagLibs RSS WebServices Plugins Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 33 2008

TagLibs: The Use Default namespace is g: Grails - Rapid Web Application Development for the Java Platform 34 2008

TagLibs: The Library The name of the Closure is the name of the tag No TLD, nor registration anywhere Grails - Rapid Web Application Development for the Java Platform 35 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Overview Controllers View / GSP TagLibs RSS WebServices Plugins Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 36 2008

Generating RSS-Feeds Grails - Rapid Web Application Development for the Java Platform 37 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Overview Controllers View / GSP TagLibs RSS WebServices Plugins Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 38 2008

Grails WebServices REST and SOAP style SOAP supported via XFire and Axis2 plugins (among others) REST supported via URL mapping Groovy features Grails - Rapid Web Application Development for the Java Platform 39 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Overview Controllers View / GSP TagLibs RSS WebServices Plugins Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 40 2008

Currently about 60 Plugins Grails - Rapid Web Application Development for the Java Platform 41 2008

Grails Plugins > grails list-plugins > grails install-plugin <name> > grails plugin-info <name> > grails create-plugin Plugins are themeselves Grails applications Plugins are provided with several hooks during install Plugin resources are added to the main application at startup Grails - Rapid Web Application Development for the Java Platform 42 2008

Grails Plugins Grails - Rapid Web Application Development for the Java Platform 43 2008

RichUI: DateChooser Grails - Rapid Web Application Development for the Java Platform 44 2008

RichUI: Flow Grails - Rapid Web Application Development for the Java Platform 45 2008

RichUI: Drag & Drop Grails - Rapid Web Application Development for the Java Platform 46 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 47 2008

Agenda What is Grails? 8 steps to a Grails Application Domain Modeling in GORM Data are always part of the game. Grails Controllers and Groovy Server Pages Grails Applications Summary Grails - Rapid Web Application Development for the Java Platform 48 2008

Summary With the advent on Web 2.0 agility is key Dynamic frameworks (Grails, Rails, Django etc.) provide this through quick iterative development with a clear productivity gain However, for large scale applications static-typing and IDE support is crucial Grails provides the ability to use a blended approach And most importantly it runs on the JVM! Grails - Rapid Web Application Development for the Java Platform 49 2008

Thank you!? www.trivadis.com Basel Baden Bern Lausanne Zurich Düsseldorf Frankfurt/M. Freiburg i. Br. Hamburg Munich Stuttgart Vienna