2006 JavaOne SM Conference | Session BOF-2521 | Rapid Web Application Development with Grails Graeme Rocher Managing Director Agilize it

Slides:



Advertisements
Similar presentations
Struts Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Advertisements

Apache Struts Technology
Web Applications Development Using Coldbox Platform Eddie Johnston.
Copyright Dr Peter Lappo Copy only with credits. 1 Building an Online Conference Booking Programme with Grails In an Hour !
Ruby on Rails by Manik Juneja Ruby On Rails. Ruby on Rails by Manik Juneja Rails is a Web Application development framework. Based on the MVC pattern.
DT211/3 Internet Application Development
DT228/3 Web Development JSP: Directives and Scripting elements.
Groovy & Grails Jean Barmash CTO, EnergyScoreCards.com
Apache Struts Technology A MVC Framework for Java Web Applications.
Session-01. Layers Struts 2 Framework The struts 2 framework is used to develop MVC-based web application. Struts 1.0 was released in June The.
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.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Stateful Web Application Development with Spring Web Flow John Case Senior Consultant Centare Group, Ltd.
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts Framework.
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Ruby on Rails: An Introduction JA-SIG Summer Conference 2007 Michael Irion The University of Tulsa.
A little engineering on Rails Robert W. Hasker. Goals Intro to the Rails framework ▫Basic concepts: MVC, Active Record ▫A bit of Ruby Using Rails to build.
Ruby on Rails. What is Ruby on Rails? Ruby on Rails is an open source full-stack web framework. It is an alternative to PHP/MySQL. It can render templates,
WebWork in Action An introduction to WebWork Patrick A. Lightbody.
Java Server Pages CS-422. What are JSPs A logical evolution of java servlets –most servlets dynamically create HTML and integrate it with some computational.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
JSP Standard Tag Library
WaveMaker Visual AJAX Studio 4.0 Training Studio Overview.
Java Server Faces Çağatay Çivici Apache MyFaces Team Member
JDeveloper 10g and JavaServer Faces: High-Performance UIs on the Web Avrom Roy-Faderman Senior Programmer May, 2006.
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
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
Introduction to Model-Glue Rachel Lehman Perpetual Intermediate Designer-Developer Introduction to Model-Glue.
By: Saurabh Dixit.  Groovy server pages  Taglibs  Validators in grails.
Grails Mansura Habiba 13 november Introduction What is Grails? Runs on the Java Virtual Machine Used Java like dynamic language Groovy Inspired.
Peter Laird. | 1 Building Dynamic Google Gadgets in Java Peter Laird Managing Architect WebLogic Portal BEA Systems.
1 Geospatial and Business Intelligence Jean-Sébastien Turcotte Executive VP San Francisco - April 2007 Streamlining web mapping applications.
MVC Concepts Basics Model-View-Controller (MVC) Concepts for Web Developers SoftUni Team Technical Trainers Software University
Selenium and Selenium on Rails. Agenda  Overview of Selenium Simple Selenium Tests Selenium IDE  Overview of Selenium on Rails  Problems with Selenium.
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
Getting started with ASP.NET MVC Dhananjay
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
Spring and DWR Frameworks for Rich Web Enterprise Application Thomas Wiradikusuma Presentation to the 20 th.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
Apache Struts Technology A MVC Framework for Java Web Applications.
1 Rails for the Ruby-Impaired John Paul Ashenfelter CTO/Transitionpoint.
Ajax 101 for CF Programmers Randy Brown – Michigan State University
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Part VI: Mapping URLs.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
National College of Science & Information Technology.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
Open Software Integrators, LLC 1 Spring Roo - IDE Research ● Basics of Spring Roo (Installation and Roo shell) ● Spring Roo, Maven, Tomcat works! ● Front.
Web Technology Solutions
JSP: Actions elements and JSTL
Google Web Toolkit Tutorial
Play Framework: Introduction
Unit 6-Chapter 2 Struts.
PHP / MySQL Introduction
Ruby on Rails by Manik Juneja
Ruby on Rails by Manik Juneja
CS5220 Advanced Topics in Web Programming Spring – Web MVC
Introduction to Grails
ESIS Consulting LLC (C) ESIS Consulting LLC. All rights reserved
CS5220 Advanced Topics in Web Programming Spring – Web MVC
Presentation transcript:

2006 JavaOne SM Conference | Session BOF-2521 | Rapid Web Application Development with Grails Graeme Rocher Managing Director Agilize it Session ID# BOF-2521

2006 JavaOne SM Conference | Session BOF-2521 | 2 Learn how to rapidly create web applications using the agile web application framework Grails Rapid Web Application Development with Grails Goal of this Talk

2006 JavaOne SM Conference | Session BOF-2521 | 3 Agenda Groovy & Grails Getting Started The Application Domain Controllers Groovy Servers Pages (GSP) Tag Libraries Ajax Support Scaffolding Java Integration

2006 JavaOne SM Conference | Session BOF-2521 | 4 Agenda Groovy & Grails Getting Started The Application Domain Controllers Groovy Servers Pages (GSP) Tag Libraries Ajax Support Scaffolding Java Integration

2006 JavaOne SM Conference | Session BOF-2521 | 5 Groovy & Grails ● Grails: MVC web framework inspired by: ● Convention over Configuration ● Don’t Repeat Yourself (DRY) ● Ruby on Rails ● Built on solid foundations: ● Spring IoC, MVC and WebFlow ● Hibernate ● SiteMesh ● Why Groovy? ● Meta-Programming ● Closure Support ● Syntactically Expressive ● Java Integration Source: Please add the source of your data here

2006 JavaOne SM Conference | Session BOF-2521 | 6 Agenda Groovy & Grails Getting Started The Application Domain Controllers Groovy Servers Pages (GSP) Tag Libraries Ajax Support Scaffolding Java Integration

2006 JavaOne SM Conference | Session BOF-2521 | 7 Getting Started ● Grails available from ● Stable & Development snapshots available ● Simple installation: ● Download & extract zip ● Set GRAILS_HOME variable ● Add $GRAILS_HOME\bin to PATH variable ● Run “grails create-app” Source: Please add the source of your data here

2006 JavaOne SM Conference | Session BOF-2521 | 8 + PROJECT_HOME + grails-app + conf + controllers + domain + i18n + services + taglib + views + lib + spring + hibernate + src + web-app Project Infrastructure Main Grails resources Additional Spring configuration Additional Hibernate mapping Web resources e.g. CSS, JavaScript etc. Java sources Jar archive libraries

2006 JavaOne SM Conference | Session BOF-2521 | 9 Command Line Targets ● Apache Ant bundled with Grails ● Many useful targets available: ● create-* (for creating Grails artifacts) ● generate-controller ● generate-views ● run-app ● test-app ● run-webtest Source: Please add the source of your data here

2006 JavaOne SM Conference | Session BOF-2521 | 10 The Data Source // data source located in grails-app/conf Class ApplicationDataSource pooled = dbCreate = url = driverClassName = username = password = “sa” } Whether connection Pooling is enabled DB Auto creation with hbm2ddl Remaining connection settings

2006 JavaOne SM Conference | Session BOF-2521 | 11 Agenda Groovy & Grails Getting Started The Application Domain Controllers Groovy Servers Pages (GSP) Tag Libraries Ajax Support Scaffolding Java Integration

2006 JavaOne SM Conference | Session BOF-2521 | 12 The Application Domain ● Domain classes hold state and implement behaviour ● They are linked together via relationships (e.g. one-to-many) ● In Java domain classes have traditionally been handled by Object-Relational Mapping (ORM) ● Grails provides simple ORM built on Hibernate Source: Please add the source of your data here

2006 JavaOne SM Conference | Session BOF-2521 | 13 Grails ORM (GORM) ● Extremely simple. No special class to extend or file to configure! class ExpenseReport Long Long relatesToMany = Set Date String employeeName } Each domain class has an ‘id’ and ‘version’ Defines one-to-many relationship to ExpenseItem

2006 JavaOne SM Conference | Session BOF-2521 | 14 Grails ORM (GORM) ● We’ve got this far, so lets define the other side! class ExpenseItem Long Long belongsTo = String Currency Integer amount } Defines the owning side of the relationship Each property maps To a column

2006 JavaOne SM Conference | Session BOF-2521 | 15 Grails Constraints ● Validation constraints can be defined using the ‘constraints’ property class ExpenseItem { constraints = { type(inList:['travel', 'accomodation']) amount(range:1..999) } Each node relates to a property Ensures the ‘type’ property Is one of the values in the list ‘amount’ must be in a range greater than 0 but less than 1000

2006 JavaOne SM Conference | Session BOF-2521 | 16 Dynamic Methods & Properties ● Grails injects methods and properties into domain classes at runtime: def r = ExpenseReport.findByEmployeeName('fred') def r = ExpenseReport.findBySubmissionDateGreaterThan(lastMonth) def reports = ExpenseReport.findAll() assert ! (new ExpenseItem().validate()) def er = new ExpenseReport(employeeName: 'Edgar').save()

2006 JavaOne SM Conference | Session BOF-2521 | 17 Agenda Groovy & Grails Getting Started The Application Domain Controllers Groovy Servers Pages (GSP) Tag Libraries Ajax Support Scaffolding Java Integration

2006 JavaOne SM Conference | Session BOF-2521 | 18 Controllers ● Controllers handle requests and prepare responses ● Response created by either delegating to a view or writing to the response ● A controller is a class containing closure properties that act on requests ● The convention used for the name of the controller and the actions within map to URIs. Source: Please add the source of your data here

2006 JavaOne SM Conference | Session BOF-2521 | 19 The Controller ● The controller and action name map to the URI: /expenseReport/list class ExpenseReportController list = { [expenseReports : ExpenseReport.list()] } The name of the class is the first token in the URI Each action is a closure property An optional model is returned as a map

2006 JavaOne SM Conference | Session BOF-2521 | 20 Data Binding & Flow Control // save save = { def e = ExpenseItem.get(params.id) e.properties = params if(e.save()){ redirect(action:show,id:e.id) } else { render( view: 'create', model:[expenseItem:e] ) } Auto-type conversion from request parameters Dynamic get method Auto-type conversion To id type Example flow control via render and redirect methods

2006 JavaOne SM Conference | Session BOF-2521 | 21 Agenda Groovy & Grails Getting Started The Application Domain Controllers Groovy Servers Pages (GSP) Tag Libraries Ajax Support Scaffolding Java Integration

2006 JavaOne SM Conference | Session BOF-2521 | 22 Groovy Server Pages ● A view technology very similar to JSP, but with Groovy as the primary language ● More expressive and concise with support for embedded GStrings & Tags ● Layout support through integration with SiteMesh ● Ability to define dynamic tag libraries Source: Please add the source of your data here

2006 JavaOne SM Conference | Session BOF-2521 | 23 A GSP Example ● The GSP for the list action is named according to convention: grails-app/views/expenseItem/list.gsp ${it.type} – amount: ${it.amount} References the model returned by the controller Embedded GString expressions

2006 JavaOne SM Conference | Session BOF-2521 | 24 Agenda Groovy & Grails Getting Started The Application Domain Controllers Groovy Servers Pages Tag Libraries Ajax Support Scaffolding Java Integration

2006 JavaOne SM Conference | Session BOF-2521 | 25 Dynamic Tag Libraries ● Easy definition of simple, logical and iterative tags: class ExpenseTagLib dateFormat = { attrs,body -> out << new SimpleDateFormat(attrs.format).format(attrs.date) } The name of the tag The body argument is a closure that can be invoked The attributes are passed as a map

2006 JavaOne SM Conference | Session BOF-2521 | 26 Dynamic Tag Libraries ● Using the tag requires no imports or configuration and can be reloaded at runtime!: Submitted: <g:dateFormat date="${report.submissionDate}" format="DD-MM-YYYY" /> <input type="hidden" name="submissionDate" value="${dateFormat( date:report.submissionDate, format:'DD-MM-YYYY')}" /> Tag called by name with the “g:” prefix Tag can also be called as a regular method!

2006 JavaOne SM Conference | Session BOF-2521 | 27 Agenda Groovy & Grails Getting Started The Application Domain Controllers Groovy Servers Pages Tag Libraries Ajax Support Scaffolding Java Integration

2006 JavaOne SM Conference | Session BOF-2521 | 28 AJAX Support ● Built in “adaptive” tag library for Ajax ● Supports Prototype, Rico, and Yahoo (Dojo coming soon) ● Tags for remote linking, asynchronous form submission etc. ● Dynamic “render” method available for rendering XML snippets, or partial templates ● Save/Reload and dynamic tag libraries make Ajax even easier

2006 JavaOne SM Conference | Session BOF-2521 | 29 Agenda Groovy & Grails Getting Started The Application Domain Controllers Groovy Servers Pages Tag Libraries Scaffolding Ajax Support Java Integration

2006 JavaOne SM Conference | Session BOF-2521 | 30 DEMO Scaffolding

2006 JavaOne SM Conference | Session BOF-2521 | 31 Agenda Groovy & Grails Getting Started The Application Domain Controllers Groovy Servers Pages Tag Libraries Scaffolding Ajax Support Java Integration

2006 JavaOne SM Conference | Session BOF-2521 | 32 Java Integration ● Now for the important bit, with Groovy and Grails you can: ● Call any existing Java library seamlessly ● Deploy as a WAR onto any JEE application server ● Write your domain model in Java, mapped with Hibernate, and still use dynamic methods! ● Take advantage of Hibernate’s power by mapping onto legacy systems. ● Use Spring’s dependency injection to integrate Controllers with existing services

2006 JavaOne SM Conference | Session BOF-2521 | 33 DEMO ECLIPSE INTEGRATION

2006 JavaOne SM Conference | Session BOF-2521 | 34 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!

2006 JavaOne SM Conference | Session BOF-2521 | 35 For More Information ● Groovy website – ● Grails website – ● Mailing lists – ● Graeme’s Blog – ● Upcoming books ‘The Definitive Guide to Grails’ by Apress and ‘Groovy in Action’ by Manning

2006 JavaOne SM Conference | Session BOF-2521 | 36 Q&A