The Definitive Guide to Grails

The Definitive Guide to Grails

Paperback(2nd Corrected ed., Corr. 3rd printing)

$42.29 $46.99 Save 10% Current price is $42.29, Original price is $46.99. You Save 10%.
View All Available Formats & Editions
Eligible for FREE SHIPPING
  • Want it by Thursday, September 27  Order now and choose Expedited Shipping during checkout.


The Definitive Guide to Grails by Graeme Rocher, Jeff Scott Brown

As modern web application developers, most of us have experienced one or many of the so-called web application frameworks that promise much, but often deliver so little. The frustration of verbose configuration and anemic APIs has led many, particularly in the Java[Trademark] community, in search of greener fields.

The aim of this book is to introduce one of those greener fields that is not so far from home. In fact, its roots are very much embedded in the Java platform that we all know and love. Grails could well be the web application framework that you've been searching for. Here, I provide you with all the information that you need to get productive quickly.

You will learn how to use the Groovy language with Grails to rapidly prototype applications, develop dynamic tag libraries, create rich domain models, and provide reusable services. If you're from a background of building applications with existing Java frameworks, such as Spring, Hibernate, and Quartz, you'll be able to build on that knowledge, because Grails leverages each of these well-known frameworks to provide a full stack experience. If you're not, Grails shields you from the technicalities of those framework APIs, leaving you to focus on what's important: the business logic in your application.

I wrote this book to spread the news that there are robust, dynamic alternatives to traditional Java web application frameworks, and to show you how you can use dynamic and statically typed code that will complement one another where appropriate.

Groovy is an incredibly powerful language, but until recently much of its power was largely undocumented. The development of Grails provides a shining example of what Groovy iscapable of when its full range of features is harnessed.

Product Details

ISBN-13: 9781590599952
Publisher: Apress
Publication date: 05/14/2009
Edition description: 2nd Corrected ed., Corr. 3rd printing
Pages: 648
Product dimensions: 7.00(w) x 9.20(h) x 1.50(d)

About the Author

Graeme Rocher is an experienced software engineer, consultant and dynamic language expert. Graeme is project lead of the open source Grails web application framework ( and author of The Definitive Guide to Grails. In Graeme's role as head of Grails development at SpringSource, the professional open source services company behind the Spring framework, Graeme leads the development of the Grails web framework and provides consulting, training and support to SpringSource's clients. Graeme is a frequent speaker at industry conferences on subjects related to Groovy, Grails and dynamic languages in Java. Prior to joining SpringSource Graeme co-founded G2One the Groovy/Grails Company which was later acquired by SpringSource.

Table of Contents

Foreword     xiv
About the Author     xvi
About the Technical Reviewers     xvii
Acknowledgments     xviii
Introduction     xix
The Search for the Holy Grail(s)     1
Trouble in Paradise     1
The Arrival of Web 2.0 Applications     23
The Power of Java     3
Grails: The Story So Far     4
Java Integration     5
Simplicity and Power     5
Lessons Learned     7
Why You Should Be Interested in Grails     7
Getting Started with Grails     8
Running the Targets     10
The Obligatory "Hello World!"     11
The Unit Tests     15
Summary     16
The Groovy Language     17
Groovy and Java: A Comparison     18
What's the Same?     18
What's Different?     18
The Basics     20
Declaring Classes     20
Language-Level Assertions     21
Groovy Strings     21
Closures     24
Lists and Maps     25
Expando Objects     27
Ranges     28
Groovy PowerFeatures     29
Everything Is an Object     29
Metaprogramming     33
Understanding Builders     34
Summary     36
The Grails Project Infrastructure     37
Overview of a Grails Project     37
Grails and the MVC Pattern     40
The M in MVC     40
The V in MVC     41
The C in MVC     41
Beyond MVC     41
Being Environmentally Friendly     41
Data Source Configuration     42
Supported Databases     46
Configuring a Custom Dialect     47
Bootstrapping a Grails Application     48
Configuring Logging     48
Enabling SQL Logging     50
Logging and Environments     50
The Grails Command-Line Utilities     50
Running on a Different Port     51
Packaging a WAR Archive     51
Using the Grails Console and Shell     52
Using the Command-Line Shell     52
The Grails Console     53
IDE Integration     54
Installing the Groovy-Eclipse Plug-in     55
Importing a Grails Project     55
Running the Grails Application from Eclipse     58
Summary     60
The Application Domain     61
Simplified ORM with Grails Object-Relational Mapping (GORM)     61
GORM Basics     62
Making Properties Optional     65
Relationships with GORM     65
Performing CRUD Operations     67
Creating Bookmarks     68
Reading a Bookmark     68
Updating the Bookmark     68
Deleting Bookmarks     69
Querying the Domain Model     69
Basic Retrieval with get and exists     69
Listing, Sorting, and Counting     70
Querying with Dynamic Finders     71
Querying with HQL     73
Querying by Example     73
Querying with Criteria     74
Mapping Inheritance     79
Validating the Domain     81
Applying Domain Constraints     82
Validating Against Constraints     84
Defining Custom Constraints     85
Performing Updates Revisited     87
Summary     88
Scaffolding     89
Dynamic Scaffolding     89
Create Operation     92
Read Operation      96
Update Operation     96
Delete Operation     101
Overriding CRUD Operations     101
Customizing Fields with Constraints     103
Static Scaffolding     104
Generating a Controller     105
Generating Views     108
Summary     110
Testing, Testing, Testing     111
Writing Effective Unit Tests     112
Using the assert Keyword     114
Using Test Data     116
Exploring GroovyTestCase     117
Testing in Practice     118
Using Mocks and Stubs     121
Mocks in Action     121
Defining Test Data with Closure Currying     123
Functional Testing with WebTest     128
Installing WebTest     128
Generating a Web Test     131
Executing Web Tests     134
Interacting with Forms     136
Summary     137
Grails Controllers     139
Introduction to Controllers     139
Setting the Default Action     141
Accessing Request Attributes     142
Using Logging     143
Working with Request Parameters     145
Understanding Flash Scope     146
Creating a Model     148
Data Binding and Type Conversion     149
Data Binding with Domain Models     150
Data Binding with the bindData Method     152
Controlling Flow with Redirects     153
Constructing a Model with Chaining     154
Rendering a Response     156
Rendering Text     157
Rendering a Specific View     157
Rendering Markup     157
Using Action Interception     158
Before Advice     159
After Advice     159
Using Interceptors for Authentication     159
Handling File Uploads     167
Working with Multipart Requests     167
Uploads and Data Binding     169
Summary     170
Groovy Server Pages     171
The Basics     171
Understanding the Model     172
Page Directives     173
Groovy Scriptlets     173
GSP as GStrings     174
Built-in Grails Tags     175
Setting Variables with Tags     175
Logical Tags     175
Iterative Tags     177
Filtering and Iteration      178
Grails Dynamic Tags     181
Linking Tags     182
Creating Forms and Fields     184
Validation and Error Handling     189
Internationalization Support     191
The message Tag     191
Using Layouts and Templates     192
An Example Layout     193
Layout-by-Convention     195
Layout with Meta Tags     195
Layouts in Action     195
Understanding Templates     200
Shared Templates     202
The Render Method Revisited     202
Paginating Data     203
Creating Custom Tags     205
Creating a Tag Library     206
Custom Tag Basics     207
Custom Tags in Action     208
Testing a Custom Tag     211
Summary     215
Ajax     217
The Basics of Ajax     217
Ajax in Action     221
Executing Code Before and After a Call     229
Handling Events     230
More on Updating Content     231
Remote Linking     231
Applying Effects     233
Working with JavaScript Events     234
Remote Form Submission     236
A Note on Ajax and Performance     238
Summary     239
Services and Jobs     241
Service Basics     241
Transactions     242
Services and Dependency Injection     243
Services in Action     244
Extended Search Capability     246
Latest Posts     252
Testing the Service     255
Scheduling Jobs with Quartz     256
Simple Jobs     256
Cron Jobs     258
Jobs in Action     260
Updating the Domain Model     262
Implementing a Controller     262
Creating the View and Template     264
Scheduling the Job     267
Testing the Job     274
Interacting with the Scheduler     278
Pausing and Resuming Jobs     280
Triggering a Job     280
Adding and Removing Jobs     280
Summary     282
Java Integration     283
Server-Side Java Integration     283
ORM Integration with Hibernate     285
Mapping with Hibernate XML     285
EJB3-Compliant Mapping     289
Using Constraints with POJO Entities     300
Retrieving the SessionFactory     302
Dependency Injection with Spring     302
Getting Hold of Useful Beans     303
Overriding Bean Definitions     306
Using Spring Controllers with Grails     306
Using Acegi Security with Grails     318
Exposing a SOAP Service with XFire     327
Summary     331
Index     333

Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews

The Definitive Guide to Grails 1 out of 5 based on 0 ratings. 1 reviews.
Anonymous More than 1 year ago