Introduction to Grails

Slides:



Advertisements
Similar presentations
May 13th, Lucek Consulting Basic Java Servlet/JSP Web Development David Lucek Lucek Consulting
Advertisements

.NET 3.5 SP1 New features Enhancements Visual Studio 2008 SP1 New features Enhancements Additional features/enhancements.
Java Script Session1 INTRODUCTION.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Apache Struts Technology
Creating Web Services with Ruby on Rails Robert Thew Internet and Web Systems II.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
DT211/3 Internet Application Development
Groovy & Grails Jean Barmash CTO, EnergyScoreCards.com
Web programming for project students Dr Jim Briggs.
Apache Struts Technology A MVC Framework for Java Web Applications.
Web Applications Basics. Introduction to Web Web features Clent/Server HTTP HyperText Markup Language URL addresses Web server - a computer program that.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Web 2.0 with AJAX Students : LASC Ioana KELEMEN Csilla POP Dan Adrian CIOBANU Dumitru Daniel Project leader : Ahmed RHIAT.
© Internna Technologies 1 IWebMvc Features, Possibilities & Goals.
UNIT-V The MVC architecture and Struts Framework.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
NextGen Technology upgrade – Synerizip - Sandeep Kamble.
Rails and Grails. To get started Make sure you have java installed You can get the sdk and jre at:
Groovy in 15 minutes… Johannes Carlén Callista Enterprise AB
|Tecnologie Web L-A Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
Java Users Group Charleston, SC June 25, 2008 Introduction to Grails by Jason McDonald.
An Introduction To Building Groovy Web Applications With Grails Jeff Brown – Principal Software Engineer Object Computing Inc.
Standalone Java Application vs. Java Web Application
1 Groovy for Java developers and testers How Java developers and testers could use Groovy to increase their efficiency AUGUST 6, 2015.
Chapter 8 Cookies And Security JavaScript, Third Edition.
By: Saurabh Dixit.  Groovy server pages  Taglibs  Validators in grails.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Grails Mansura Habiba 13 november Introduction What is Grails? Runs on the Java Virtual Machine Used Java like dynamic language Groovy Inspired.
Lap Around Visual Studio 2008 &.NET 3.5 Enhancements.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
2006 JavaOne SM Conference | Session BOF-2521 | Rapid Web Application Development with Grails Graeme Rocher Managing Director Agilize it
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
INTEGRATION OF BACKBONE.JS WITH SPRING 3.1. Agenda New Features and Enhancements in Spring 3.1 What is Backbone.js and why I should use it Spring 3.1.
An Introduction to JavaServer™ Pages Prepared by Nicole Swan.
An Introduction to JavaServer™ Pages Prepared by Nicole Swan.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
Implementation Struts Framework for well-architectured web applications Model-View-Controller design pattern.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Apache Struts Technology A MVC Framework for Java Web Applications.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
1 NetBeans New and Cool Sun Microsystems, Inc.. 2 Goal of the Talk Learn how NetBeans IDE can help you become more productive Learn about the new features.
Architecture of Professionals.az Ziya Askerov April 2013
JSP: Actions elements and JSTL
Web Routing Designing an Interface
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
Internationalization
Google Web Toolkit Tutorial
Play Framework: Introduction
4166 Review.
Scripted Page Web App Development (Java Server Pages)
Introduction to CodeIgniter (CI)
PHP Training at GoLogica in Bangalore
Knowledge Byte In this section, you will learn about:
Build Better Apps with MEAN.
Course Name: QTP Trainer: Laxmi Duration: 25 Hrs Session: Daily 1 Hr.
Introduction to Struts
Introduction to JBoss application server
ESIS Consulting LLC (C) ESIS Consulting LLC. All rights reserved
PHP.
Chapter 15 Introduction to Rails.
International Living Atlases Workshop Madrid 2018
SDMX IT Tools SDMX Registry
Presentation transcript:

Introduction to Grails by Jason McDonald Java Users Group Charleston, SC June 25, 2008

Getting Started

Grails Basics Open Source Fully integrated with Java Groovy based Uses ANTLR to compile Groovy down to JVM compatible bytecode Predicated on DRY principle

Underlying Technologies Spring Hibernate Log4J Junit Quartz Ant

Native Support HSQL MySQL Servlet container servers AJAX and DHTML Jetty Tomcat AJAX and DHTML Dojo Prototype Yahoo!

Installation Visit http://www.grails.org Download and extract files Create GRAILS_HOME environment variable Add %GRAILS_HOME% to PATH environment variable That’s it!

Grails Structure

Goovy Roots Built on top of Java Very similar syntax to java Supports closures Method returns can be slightly different Case sensitive No semi-colons needed All classes end in .groovy

Conditional Environments Environment conditionals allow for variations for a specific environment Database Initialization options More Three environment choices Development Testing Production

Script Based Code Generation grails create-app [app name] grails create-controller [controller name] grails create-domain-class [class name] grails create-service [service name] grails create-unit-test [test name] grails create-tag-lib [taglib name] grails generate-all [class name] grails generate-views [class name]

Building, Deploying, and Managing grails clean grails compile grails console grails doc grails install-plugin grails run-app grails war

Important Files conf/DataSource.groovy conf/UrlMapping.groovy Database connections conf/UrlMapping.groovy Routing conf/BootStrap.groovy Bootstrap file conf/Config.groovy Configurations (MIME mappings, more…)

Routing Route rules found in conf/UrlMapping.groovy Default route: application/controller/action/id[?params] Additional rules and restrictions can be applied here static mappings = { "/product/$id?"(controller:"product"){ action = [GET:"show", PUT:"update", DELETE:"delete", POST:"save"] } }

Databases db configuration is in conf/DataSource.groovy Can define at environment level or global level Defaults to HSQL Change to MySQL by: Dropping MySQL connector in the lib Changing DataSource.groovy to point at MySQL

Database Create Scheme dbCreate create-drop: creates tables on startup and drops them on shutdown (DEV) create: creates tables on startup, deletes data on shutdown (DEV, TEST) update – creates tables on startup, saves data between restarts (TEST, PROD)

Grails MVC

MVC Framework Standard MVC implementation Sits on top of Spring MVC Reduces repetition of XML developers must maintain Gives access to Spring DSL

Views Groovy Server Pages GSP extension Based on JSP pages Use Tag libraries Expressions similar to JSP EL but allows any expression within ${…}

Tag Libraries Ordering and sorting <g:sortableColumn property="releaseDate" defaultOrder="desc" title="Release Date" titleKey="book.releaseDate" /> Form display <g:form name="myForm" action="myaction" id="1"> <g:passwordField name="myPasswordField“ value="${myPassword}" /> ... </g:form> Formatting <g:formatDate format="yyyy-MM-dd" date="${date}"/>

Custom Tag Libraries Custom tag libraries are just groovy classes that end with TagLib Defaults to ‘g’ namespaces unless declared Closure defines actual tag: class FormattingTagLib { static namespace = ‘fmt’ def dateFormat = { attrs -> out << new java.text.SimpleDateFormat( ‘dd-MM-yyyy’).format(attrs.date) } } <fmt:dateFormat date=‘${plan.effDate}’ />

Internationalization Support Based on Java i18n specifications Define properties files with language specific entries Views can read i18n entries with a tag: <g:message code=‘my.message’ args=‘${[‘One’, ‘Two’]}’/> Tag libraries can read entries with code: g.message(code: ‘my.message’, args: [‘One’, ‘Two’])

Models POGOs Fields default to private Getters and setters provided automatically Must use wrapper objects – no primitives (1.5?) Field validation defined within: static constraints = { date(nullable: false) } Can define custom messages using convention: className.propertyName.constraint = ‘’Err msg’’ Automatic parameter mapping from view book.properties = params

GORM Grails Object Relational Mapping Uses Hibernate3 Dynamic methods for finding Book.findByTitle(“The Dark Tower“) Book.findByTitleAndAuthor(“The Dark Tower”, “Stephen King” Book.findByTitle(“Christine”, [sort: ‘edition’, order: ‘asc’] ) Relational mapping defined within One to many: static hasMany = [ attendances:Attendance ] One to one: Attendance attendance

GORM Caching Provides the same caching mechanisms that can be found with Hibernate3 Updates to DataSource.groovy can toggle caching: hibernate { cache.use_second_level_cache = true cache.use_query_cache = true cache.provider_class = ‘org.hibernate.cache.EhCacheProvider’ }

Controllers House actions (methods) that respond to a request Actions should map to GSP of same name index is the default action Can define the method each action is allowed: def allowedMethods = [save:'POST', update:'POST'] GET is the default Auto scaffolding sets up CRUD without files def scaffold = true // In Controller class

Action Responses All actions respond in one of three ways: redirect Equivalent ot response.sendRedirect Can specify actions, controller, params, and more return Returns a value and calls a GSP of the same name (action method ‘go’ will forward to go.gsp) render Calls a GSP by name Has the ability to pass arguments

Grails in Action

Web Services REST SOAP Provide RESTful mappings in UrlMappings.groovy Implement controller to accept and return marshalled data SOAP Supported through XFire plug-in Simply expose a service: static expose = [‘xfire’]

Testing Test framework based on JUnit Unit tests Integration tests By convention uses mock objects Integration tests By convention use real objects Functional tests Supports Canoo WebTest integration

Running the Application Bootstrapping data Allows for initialization and test data Jetty Server Specify port and environment on command line grails dev –Dserver.port=9999 run-app Tomcat As war Exploded

The Example

Requirements Application needs to: Store meetings, people, and which meetings each person attends People should store first and last name Meetings should store date and subject of meeting Must have full CRUD capability Must be web based Must be able to integrate with Java environments (to meet future integration needs)

Open Discussion