Top Banner
Web Development The Grails Framework
34

Web Development With Grails

Jul 21, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Web Development With Grails

Web Development

The Grails Framework

Page 2: Web Development With Grails

Grails

Grails is a full-stack web application framework

built on top of such tried and true open source

frameworks as:

Spring, Hibernate, Ant, JUnit, SiteMesh and the

Groovy language.

Full-stack means the framework provides components and

artifacts for all tiers of a web application.

Grails is a good example of software reuse

Page 3: Web Development With Grails

Full-stack vs. extensible framework

Full-stack means all the components are pre-

integrated into the framework!

- Less flexibility

+ Extremely easy configuration process

On the other hand, an extensible framework lets

you decide on individual components that

would work together in you framework

Apache Struts: http://struts.apache.org/

Page 4: Web Development With Grails

Technical Info

1. First release: 0.1 on March 29, 2006

2. Stable release: 2.2.1 on February 25, 2013

3. Official web site : http://www.grails.org

4. License: Apache License 2.0

5. Programming language used: Groovy

6. Platform: Cross- platform (JVM)

7. Company: VMware, Inc.

Page 5: Web Development With Grails

Five Strong Pillars

1. Spring for workflows and dependency

injection

2. Hibernate to manage persistence (ORM)

3. SiteMesh for composition of views

4. Ant for managing the development process

5. Groovy, a dynamic language for the JVM

Grails makes it easy to use these powerful tools

Page 6: Web Development With Grails

Main Features

• Coding by convention paradigm (also known as “Convention over configuration”)

– Things behave as expected without having to write configuration files

• DRY: Don't repeat yourself!

– “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system”(*)

– So, reduce repetition of information of all kinds

(*) The Pragmatic Programmer by Andrew Hunt and David Thomas, 1999.

Page 7: Web Development With Grails

Main Features (2)

• The MVC pattern: the components of a system

should be organized in three layers, according

to their mission: DATA layer, PRESENTATION

layer and CONTROL layer.

– When working in Grails, we generated

components in each layer and is the environment

that is responsible for connecting with each other

and ensure smooth operation.

Page 8: Web Development With Grails

The MVC pattern

• Data layer

contains components that represent and manage

data handled by the application

• Presentation layer

contains the components that are responsible for

showing the user the current state of the data

model, and present the different actions available

Page 9: Web Development With Grails

The MVC pattern (2)

• Control layer

Contains the components that receive user commands,

manage the application of business logic on the data

model, and determine which view must be shown.

In Grails, normally the business logic is

implemented in a fourth layer:

• Service layer

Contains the components responsible for implementing

the business logic of our application.

Page 10: Web Development With Grails

How it works

Available at: http://www.youtube.com/watch?feature=player_embedded&v=XrDXqoomws4

Page 11: Web Development With Grails

The Entire Environment

Page 12: Web Development With Grails

The Entire Environment (2)

Page 13: Web Development With Grails

The Entire Environment (3)

Page 14: Web Development With Grails

Basic Grails Requirements

• A Java Development Kit (JDK) installed version

1.6 or above.

java –version

• A valid JAVA_HOME environment variable

pointing to the location of this installation

For example: C:\Program Files\Java\jdk1.7.0

Page 15: Web Development With Grails

Installing Grails

1. Download the Grails archive from

http://grails.org/download and extract it to a

local directory.

For example: C:\grails\grails-2.2.1

2. Set a GRAILS_HOME environment variable to

that directory

For example: C:\grails\grails-2.2.1\

Page 16: Web Development With Grails

Installing Grails (2)

3. Add GRAILS_HOME/bin to your path variable

– For example: C:\grails\grails-2.2.1\bin\

4. For checking that the installation process

was successful open the console and type:

grails –version or grails help

You should receive an appropriate response in any

case

Page 17: Web Development With Grails

Installation Video Tutorials

• Installing Grails on Windowshttp://www.grailsexample.net/installing-a-grails-development-environment-on-windows/

• Installing Grails on Linuxhttp://www.grailsexample.net/installing-a-grails-development-environment-on-linux/

Page 18: Web Development With Grails

Creating an Application: create-app

• The grails command is the most important

one:

grails [command-name]

• To create a grails application just use the

create-app command:

grails create-app AutoMart

This will create a new directory (AutoMart) inside

the current one that contains the project.

Page 19: Web Development With Grails

Folders Organization

Grails automatically organizes

source code artifacts

according to the MVC pattern

Placing source files in certain

directories and naming them in

certain ways are examples of the

many conventions in Grails

Path: AutoMart\grails-app

Page 20: Web Development With Grails

Creating an Application:

create-domain-class

• Change to AutoMart directory and type:

grails create-domain-class Car

• After a moment this command will finish and you will get:

Created file grails-app/domain/automart/Car.groovyCreated file test/unit/automart/CarTests.groovy

Create-app and create-domain-class are Grails scripts. Use grails help to see which other scripts are provided by grails

Page 21: Web Development With Grails

Creating an Application:

editing a domain class

Just add these

attributes to the Car

class

Page 22: Web Development With Grails

Creating an Application: generate-all

• To have a complete working web application,

with pages for creating, displaying, editing and

listing Car instances you can use the generate-

all command:

grails generate-all Car

Page 23: Web Development With Grails

Running the Application

• You can launch the application using the

command run-app:

grails run-app

• Grails runs on port 8080 by default.

• So Navigate to

http://localhost:8080/AutoMart

and look around.

Page 24: Web Development With Grails

The Application is Running!

Page 25: Web Development With Grails

Grails Environment

• A web server

• A Java application server

• Database environment

Page 26: Web Development With Grails

Groovy/Grails Tool Suite

GGTS provides an Eclipse-powered development

environment for building Groovy and Grails applications

Groovy/Grails Tool Suite 3.2.0 release

They still recommend to use the Eclipse 3.8-based version

Page 27: Web Development With Grails

Where to get GGTS stuff

The search is over! www.grails.org

Page 28: Web Development With Grails

How it looks

Page 29: Web Development With Grails

Setting up a Grails Project

Available at: http://www.youtube.com/watch?feature=player_embedded&v=qcZ6FWmIuJc

Page 30: Web Development With Grails

The Online Course: Part 1

http://www.grailsexample.net/course-outline/

Page 31: Web Development With Grails

The Online Course: Part 2

http://www.grailsexample.net/course-outline/

Page 32: Web Development With Grails

An Online Course: Part 3

http://www.grailsexample.net/course-outline/

Page 33: Web Development With Grails

Books

• There is a list of books at the GRAILS web site: http://grails.org/Documentation

• Christopher M. Judd, Joseph Faisal Nusairat, and James Shingler. Beginning Groovy and Grails. Apress, 2008.

• Nacho Brito. Manual de desarrollo web con GRAILS. ediciones ágiles, 2009.

• Glen Smith and Peter Ledbrook. Grails in Action. Manning Publications Co., 2009.

Page 34: Web Development With Grails

Books (2)

• Graeme Rocher and Jeff Brown. The Definitive Guide to Grails, 2nd Edition. Apress, 2009.

• Scott Davis and Jason Rudolph. Getting Started with Grails, 2nd Edition. C4Media Inc., 2010

• Dave Klein. Getting Started with Grails. DZone Refcardz#60.

• Dierk König. Groovy. DZone Refcardz #15.

• Tim Downey, Guide to Web Development with Java. Springer-Verlag London Limited, 2012