The Definitive Guide to Grails, Second Edition

Book description

The rise of Ruby on Rails has signified a huge shift in how we build web applications today; it is a fantastic framework with a growing community. There is, however, space for another such framework that integrates seamlessly with Java. Thousands of companies have invested in Java, and these same companies are losing out on the benefits of a Rails–like framework. Enter Grails.

Grails is not just a Rails clone. It aims to provide a Rails–like environment that is more familiar to Java developers and employs idioms that Java developers are comfortable using, making the adjustment in mentality to a dynamic framework less of a jump. The concepts within Grails, like interceptors, tag libs, and Groovy Server Pages (GSP), make those in the Java community feel right at home.

Grails' foundation is on solid open source technologies such as Spring, Hibernate, and SiteMesh, which gives it even more potential in the Java space: Spring provides powerful inversion of control and MVC, Hibernate brings a stable, mature object relational mapping technology with the ability to integrate with legacy systems, and SiteMesh handles flexible layout control and page decoration.

Grails complements these with additional features that take advantage of the coding–by–convention paradigm such as dynamic tag libraries, Grails object relational mapping, Groovy Server Pages, and scaffolding.

Graeme Rocher, Grails lead and founder, and Jeff Brown bring you completely up–to–date with their authoritative and fully comprehensive guide to the Grails framework. You'll get to know all the core features, services, and Grails extensions via plug–ins, and understand the roles that Groovy and Grails are playing in the changing Web.

What you'll learn

  • Discover how the Web is changing and the role the Groovy language and its Rails framework play

  • Get to know the Grails Project and its domains, services, filters, controllers, views, testing, and plug–ins

  • Experience the availability of plug–ins for Rich Client and Ajax, web services, performance/utilities, scheduling, security, functionality, and even Persistence

  • See how Grails works with other frameworks like Spring, Wicket, Hibernate, and more

  • Create custom plug–ins in Grails

Who this book is for

This book is for everyone who is looking for a more agile approach to web development with a dynamic scripting language such as Groovy. This includes a large number of Java developers who have been enticed by the productivity gains seen with frameworks such as Ruby on Rails, JRuby on Rails, etc. The Web and its environment is a perfect fit for easily adaptable and concise languages such as Groovy and Ruby, and there is huge interest from the developer community in general to embrace these languages.

Table of contents

  1. Title Page
  2. Dedication
  3. Contents at a Glance
  4. Contents
  5. About the Authors
  6. About the Technical Reviewer
  7. Acknowledgments
  8. Introduction
    1. Who This Book Is For
    2. How This Book Is Structured
    3. Conventions
    4. Prerequisites
    5. Downloading the Code
    6. Contacting the Authors
  9. CHAPTER 1: The Essence of Grails
    1. Simplicity and Power
    2. Grails, the Platform
    3. Living in the Java Ecosystem
    4. Getting Started
    5. Creating Your First Application
    6. Summary
  10. CHAPTER 2: Getting Started with Grails
    1. What Is Scaffolding?
    2. Creating a Domain
    3. Dynamic Scaffolding
    4. Static Scaffolding
    5. Being Environmentally Friendly
    6. Configuring Data Sources
    7. Deploying the Application
    8. Summary
  11. CHAPTER 3: Understanding Domain Classes
    1. Persisting Fields to the Database
    2. Validating Domain Classes
    3. Using Custom Validators
    4. Understanding Transient Properties
    5. Customizing Your Database Mapping
    6. Building Relationships
    7. Extending Classes with Inheritance
    8. Embedding Objects
    9. Testing Domain Classes
    10. Summary
  12. CHAPTER 4: Understanding Controllers
    1. Defining Controllers
    2. Creating a Model
    3. Rendering a View
    4. Performing Data Binding
    5. Working with Command Objects
    6. Imposing HTTP Method Restrictions
    7. Controller IO
    8. Using Simple Interceptors
    9. Testing Controllers
    10. Controllers in Action
    11. Summary
  13. CHAPTER 5: Understanding Views
    1. The Basics
    2. Built-in Grails Tags
    3. Grails Dynamic Tags
    4. Creating Custom Tags
    5. Summary
  14. CHAPTER 6: Mapping URLs
    1. Understanding the Default URL Mapping
    2. Including Static Text in a URL Mapping
    3. Removing the Controller and Action Names from the URL
    4. Embedding Parameters in a Mapping
    5. Specifying Additional Parameters
    6. Mapping to a View
    7. Applying Constraints to URL Mappings
    8. Including Wildcards in a Mapping
    9. Mapping to HTTP Request Methods
    10. Mapping HTTP Response Codes
    11. Taking Advantage of Reverse URL Mapping
    12. Defining Multiple URL Mappings Classes
    13. Testing URL Mappings
    14. Summary
  15. CHAPTER 7: Internationalization
    1. Localizing Messages
    2. Using Parameterized Messages
    3. Using messageSource
    4. Summary
  16. CHAPTER 8: Ajax
    1. The Basics of Ajax
    2. Ajax in Action
    3. Changing Your Ajax Provider
    4. Asynchronous Form Submission
    5. Executing Code Before and After a Call
    6. Handling Events
    7. Fun with Ajax Remote Linking
    8. Adding Effects and Animation
    9. Ajax-Enabled Form Fields
    10. A Note on Ajax and Performance
    11. Summary
  17. CHAPTER 9: Creating Web Flows
    1. Getting Started with Flows
    2. Flows in Action
    3. Summary
  18. CHAPTER 10: GORM
    1. Persistence Basics
    2. Associations
    3. Querying
    4. Configuring GORM
    5. The Semantics of GORM
    6. Transactions in GORM
    7. Detached Objects
    8. Performance Tuning GORM
    9. Locking Strategies
    10. Events Auto Time Stamping
    11. Summary
  19. CHAPTER 11: Services
    1. Service Basics
    2. Services and Dependency Injection
    3. Services in Action
    4. Transactions
    5. Scoping Services
    6. Testing Services
    7. Exposing Services
    8. Summary
  20. CHAPTER 12: Integrating Grails
    1. Grails and Configuration
    2. Understanding Grails' Build System
    3. Integration with Apache Ant
    4. Dependency Resolution with Ivy
    5. Code Coverage with Cobertura
    6. Continuous Integration with Hudson
    7. Adding Support to Your Favorite IDE
    8. Integration with E-mail Servers
    9. Scheduling Jobs
    10. Deployment
    11. Summary
  21. CHAPTER 13: Plugins
    1. Plugin Basics
    2. Plugins in Action
    3. Summary
  22. CHAPTER 14: Security
    1. Securing Against Attacks
    2. Using Dynamic Codecs
    3. Authentication and Authorization
    4. Grails Filters
    5. The JSecurity Plugin
    6. Limiting Access Through URL Mappings
    7. Summary
  23. CHAPTER 15: Web Services
    1. REST
    2. Atom and RSS
    3. SOAP
    4. Summary
  24. CHAPTER 16: Leveraging Spring
    1. Spring Basics
    2. Spring and Grails
    3. Spring in Action
    4. Summary
  25. CHAPTER 17: Legacy Integration with Hibernate
    1. Legacy Mapping with the ORM DSL
    2. Mapping with Hibernate XML
    3. Summary
  26. APPENDIX: The Groovy Language
    1. Groovy and Java: A Comparison
    2. The Basics
    3. Groovy Power Features
    4. Summary
  27. Index

Product information

  • Title: The Definitive Guide to Grails, Second Edition
  • Author(s): Graeme Rocher, Jeff Brown
  • Release date: January 2009
  • Publisher(s): Apress
  • ISBN: 9781590599952