Contents

About the Authors

About the Technical Reviewer

Acknowledgments

Introduction


CHAPTER 1 The Essence of Grails

Simplicity and Power

Grails, the Platform

Living in the Java Ecosystem

Getting Started

Creating Your First Application

Step 1: Creating the Application

Step 2: Creating a Controller

Step 3: Printing a Message

Step 4: Testing the Code

Step 5: Running the Tests

Step 6: Running the Application

Summary

CHAPTER 2 Getting Started with Grails

What Is Scaffolding?

Creating a Domain

Dynamic Scaffolding

The Create Operation

The Read Operation

The Update Operation

The Delete Operation

Static Scaffolding

Generating a Controller

Generating the Views

Being Environmentally Friendly

Configuring Data Sources

The DataSource.groovy File

Configuring a MySQL Database

Configuring a JNDI Data Source

Supported Databases

Deploying the Application

Deployment with run-war

Deployment with a WAR file

Summary

CHAPTER 3 Understanding Domain Classes

Persisting Fields to the Database

Validating Domain Classes

Using Custom Validators

Understanding Transient Properties

Customizing Your Database Mapping

Building Relationships

Extending Classes with Inheritance

Embedding Objects

Testing Domain Classes

Summary

CHAPTER 4 Understanding Controllers

Defining Controllers

Setting the Default Action

Logging

Logging Exceptions

Accessing Request Attributes

Using Controller Scopes

Understanding Flash Scope

Accessing Request Parameters

Rendering Text

Redirecting a Request

Creating a Model

Rendering a View

Finding the Default View

Selecting a Custom View

Rendering Templates

Performing Data Binding

Validating Incoming Data

The Errors API and Controllers

Data Binding to Multiple Domain Objects

Data Binding with the bindData Method

Data Binding and Associations

Working with Command Objects

Defining Command Objects

Using Command Objects

Imposing HTTP Method Restrictions

Implementing an Imperative Solution

Taking Advantage of a Declarative Syntax

Controller IO

Handling File Uploads

Reading the Request InputStream

Writing a Binary Response

Using Simple Interceptors

Before Advice

After Advice

Testing Controllers

Controllers in Action

Creating the gTunes Home Page

Adding the User Domain Class

Adding a Login Form

Implementing Registration

Testing the Registration Code

Allowing Users to Log In

Testing the Login Process

Summary

CHAPTER 5 Understanding Views

The Basics

Understanding the Model

Page Directives

Groovy Scriptlets

GSP as GStrings

Built-in Grails Tags

Setting Variables with Tags

Logical Tags

Iterative Tags

Filtering and Iteration

Grails Dynamic Tags

Linking Tags

Creating Forms and Fields

Validation and Error Handling

Paginating Views

Rendering GSP Templates

Creating Custom Tags

Creating a Tag Library

Custom Tag Basics

Testing a Custom Tag

Summary

CHAPTER 6 Mapping URLs

Understanding the Default URL Mapping

Including Static Text in a URL Mapping

Removing the Controller and Action Names from the URL

Embedding Parameters in a Mapping

Specifying Additional Parameters

Mapping to a View

Applying Constraints to URL Mappings

Including Wildcards in a Mapping

Mapping to HTTP Request Methods

Mapping HTTP Response Codes

Taking Advantage of Reverse URL Mapping

Defining Multiple URL Mappings Classes

Testing URL Mappings

Summary

CHAPTER 7 Internationalization

Localizing Messages

Defining User Messages

Retrieving Message Values

Using URL Mappings for Internationalization

Using Parameterized Messages

Using java.text.MessageFormat

Using the message Tag for Parameterized Messages

Using Parameterized Messages for Validation

Using messageSource

Summary

CHAPTER 8 Ajax

The Basics of Ajax

Ajax in Action

Changing Your Ajax Provider

Asynchronous Form Submission

Executing Code Before and After a Call

Handling Events

Fun with Ajax Remote Linking

Adding Effects and Animation

Ajax-Enabled Form Fields

A Note on Ajax and Performance

Summary

CHAPTER 9 Creating Web Flows

Getting Started with Flows

Defining a Flow

Defining the Start State

Defining End States

Action States and View States

Flow Scopes

Flows, Serialization, and Flow Storage

Triggering Events from the View

Transition Actions and Form Validation

Subflows and Conversation Scope

Flows in Action

Updating the Domain

Updating the View

Defining the Flow

Adding a Start State

Implementing the First View State

Data Binding and Validation in Action

Action States in Action

Reusing Actions with Closures

Using Command Objects with Flows

Dynamic Transitions

Verifying Flow State with Assertions

Testing Flows

Summary

CHAPTER 10 GORM

Persistence Basics

Reading Objects

Listing, Sorting, and Counting

Saving, Updating, and Deleting

Associations

Relationship Management Methods

Transitive Persistence

Querying

Dynamic Finders

Criteria Queries

Query by Example

HQL and SQL

Pagination

Configuring GORM

SQL Logging

Specifying a Custom Dialect

Other Hibernate Properties

The Semantics of GORM

The Hibernate Session

Session Management and Flushing

Obtaining the Session

Automatic Session Flushing

Transactions in GORM

Detached Objects

The Persistence Life Cycle

Reattaching Detached Objects

Merging Changes

Performance Tuning GORM

Eager vs. Lazy Associations

Batch Fetching

Caching

Inheritance Strategies

Locking Strategies

Events Auto Time Stamping

Summary

CHAPTER 11 Services

Service Basics

Services and Dependency Injection

Services in Action

Defining a Service

Using a Service

Transactions

Scoping Services

Testing Services

Exposing Services

Summary

CHAPTER 12 Integrating Grails

Grails and Configuration

Configuration Basics

Environment-Specific Configuration

Configuring Logging

Stack Trace Filtering

Externalized Configuration

Understanding Grails' Build System

Creating Gant Scripts

Command-Line Variables

Parsing Command-Line Arguments

Documenting Your Scripts

Reusing More of Grails

Bootstrapping Grails from the Command Line

Gant in Action

Integration with Apache Ant

Dependency Resolution with Ivy

Code Coverage with Cobertura

Continuous Integration with Hudson

Adding Support to Your Favorite IDE

IntelliJ

NetBeans

Eclipse

TextMate

Remote Debugging with an IDE

Integration with E-mail Servers

Scheduling Jobs

Installing the Quartz Plugin

Simple Jobs

Cron Jobs

Interacting with the Scheduler

Scheduling Jobs

Pausing and Resuming Jobs

Triggering a Job

Adding and Removing Jobs

Jobs in Action

Deployment

Deploying with Grails

Deploying to a Container

Application Versioning and Metadata

Customizing the WAR

Populating the Database with BootStrap Classes

Summary

CHAPTER 13 Plugins

Plugin Basics

Plugin Discovery

Plugin Installation

Local Plugins

Creating Plugins

Providing Plugin Metadata

Supplying Application Artefacts

Plugin Hooks

Plugin Variables

Custom Artefact Types

Providing Spring Beans

Dynamic Spring Beans Using Conventions

Using Metaprogramming to Enhance Behavior

Plugin Events and Application Reloading

Modifying the Generated WAR Descriptor

Packaging and Distributing a Grails Plugin

Local Plugin Repositories

Plugins in Action

Plugins to Add Behavior

Plugins for Application Modularity

Summary

CHAPTER 14 Security

Securing Against Attacks

SQL or HQL Injection

Groovy Injection

Cross-Site Scripting (XSS)

XSS and URL Escaping

Denial of Service (DoS)

Batch Data Binding Vulnerability

Using Dynamic Codecs

Authentication and Authorization

Grails Filters

The JSecurity Plugin

Authentication Realms

Subjects and Principals

Roles and Permissions

JSecurity in Action

Limiting Access Through URL Mappings

Summary

CHAPTER 15 Web Services

REST

RESTful URL Mappings

Content Negotiation

Content Negotiation with the ACCEPT Header

The ACCEPT Header and Older Browsers

Content Negotiation with the CONTENT_TYPE Header

Content Negotiation Using File Extensions

Content Negotiation with a Request Parameter

Content Negotiation and the View

Marshaling Objects to XML

Marshaling Objects to JSON

Unmarshaling XML or JSON

REST and Security

Atom and RSS

Creating RSS and Atom Feeds

RSS and Atom Link Discovery

SOAP

SOAP Web Services via Plugins

Calling SOAP from the Client

Summary

CHAPTER 16 Leveraging Spring

Spring Basics

Spring and Grails

Dependency Injection and Grails

The BeanBuilder DSL

Spring in Action

Integrating JMS with Spring JMS

Mixing Groovy and Java with Spring

Summary

CHAPTER 17 Legacy Integration with Hibernate

Legacy Mapping with the ORM DSL

Changing Table and Column Name Mappings

Changing Association Mappings

Understanding Hibernate Types

Changing the Database Identity Generator

Using Composite Identifiers

Mapping with Hibernate XML

EJB 3–Compliant Mapping

Using Constraints with POJO Entities

Summary

APPENDIX The Groovy Language

Groovy and Java: A Comparison

What's the Same?

What's Different?

The Basics

Declaring Classes

Language-Level Assertions

Groovy Strings

Closures

Lists, Maps, and Ranges

Expando Objects

Ranges

Groovy Power Features

Everything Is an Object

Metaprogramming

Understanding Builders

Summary

Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset