Grails 1.1 Web Application Development


Grails 1.1 Web Application Development
eBook: $23.99
Formats: PDF, PacktLib, ePub and Mobi formats
$17.99
save 25%!
Print + free eBook + free PacktLib access to the book: $63.98    Print cover: $39.99
$39.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
  • Ideal for Java developers new to Groovy and Grails—this book will teach you all you need to create web applications with Grails
  • Create, develop, test, and deploy a web application in Grails
  • Take a step further into Web 2.0 using AJAX and the RichUI plug-in in Grails
  • Packed with examples and clear instructions to lead you through the development and deployment of a Grails web application

Book Details

Language : English
Paperback : 328 pages [ 235mm x 191mm ]
Release Date : May 2009
ISBN : 1847196683
ISBN 13 : 9781847196682
Author(s) : Jon Dickinson
Topics and Technologies : All Books, Web Development, Java, Open Source, Web Development


Table of Contents

Preface
Chapter 1: Getting Started with Grails
Chapter 2: Managing Users with Scaffolding
Chapter 3: Posting Messages
Chapter 4: Introduction to Groovy
Chapter 5: Authentication with JSecurity Plug-in
Chapter 6: Testing
Chapter 7: File Sharing
Chapter 8: More GORM and Criteria
Chapter 9: Services
Chapter 10: Managing Content through Tagging
Chapter 11: AJAX and RIA Frameworks
Chapter 12: Searching, RSS, and REST Services
Chapter 13: Build Your Own Plug-in
Chapter 14: Deployment and the Real World
Index
  • Chapter 1: Getting Started with Grails
    • Why Grails?
      • Less configuration
      • Faster setup
      • Shorter develop/test cycle
      • Consistent development environment
      • Domain-specific language for web development
      • Fewer dependencies
    • Installing Grails
    • Build a team communication portal
    • Summary
  • Chapter 2: Managing Users with Scaffolding
    • What is scaffolding?
    • Create the domain classes
      • Create the User domain class
      • Create the Role domain class
    • Creating controllers to enable scaffolding
    • Control through constraints
    • Meeting the relations
      • Relating roles and users
      • Ordering fields through constraints
    • Bootstrapping demo data
    • Summary
  • Chapter 3: Posting Messages
    • Message domain class
    • Rendering a form
      • Message controller
      • Groovy Server Pages
      • Create message view
      • Grails layouts
      • Show the form
    • Handling user input
      • Binding the request to the domain
      • Validate and save
      • Flash scope
      • Redirect
      • Render validation errors
      • Feedback to the user
    • Create a home page
      • HomeController
        • List all messages
      • Home page view
    • Styles and navigation
      • Set the default page
      • Update the layout
    • Tidying up
      • HTML encoding
      • Overriding validation error messages
    • Summary
  • Chapter 4: Introduction to Groovy
    • What is Groovy?
      • Object-Oriented
      • Dynamic
      • Functional
      • Loosely typed and strongly typed
    • Why Groovy?
      • Familiar syntax
      • Direct integration with Java
    • Running Groovy
      • Installing Groovy
      • Groovy shell
      • Groovy console
      • Execute Groovy scripts
      • Groovy classes and scripts
    • Groovy Features
      • Semicolons
      • Strings
      • Numbers
      • Lists
      • Maps
      • Ranges
      • Truth and equality
      • Closures
      • Plain old Groovy objects
      • Metaprogramming
        • Adding dynamic behavior
        • The great pretender
      • Builders
    • Summary
  • Chapter 5: Authentication with JSecurity Plug-in
    • Where to find plug-ins?
    • Installing a plug-in
    • Configuring JSecurity plug-in
      • How does JSecurity work?
      • More about realms
      • Create a simple realm
        • Implement authenticate
        • Dynamic finders
        • Implement hasRole
      • Install the authentication controller
      • The authentication filter
      • Password encryption
    • Add the missing pieces
      • Encryption of users' passwords
      • Permission denied page
      • Sign out link
    • Who posted that?
      • Relate messages to users
      • Making it happen
      • Showing the user
        • Hibernate lazy loading
        • Eager load users
    • Summary
  • Chapter 6: Testing
    • Writing unit tests
      • Why we write unit tests
        • Confidence in code
        • Improve design
        • Developer productivity
        • Document code
      • How to write unit tests
        • Test discreet units of code
        • Trust your libraries
        • Test your production code
        • Descriptive test names
        • Test one thing at a time
    • JUnit refresher
      • SetUp and TearDown
      • Asserting expectations
    • Unit tests in Grails
      • Groovy test extensions
      • Create a grails test
      • Running our tests
      • Grails testing plug-in
        • Testing Metacontroller
        • Testing validation
      • Limitations of Grails in unit tests
    • Integration testing
      • External dependencies
      • Repeatable tests
    • Integration tests in Grails
      • BootStrap for environments
    • Functional testing
      • Environment setup
      • Repeatable tests
      • Test performance
      • Fragility of tests
      • Making tests understandable
    • Functional testing In Grails
      • Benefits of functional testing in Grails
      • Installing the functional testing plug-in
    • Testing guidance
    • Summary
  • Chapter 7: File Sharing
    • File domain object
    • FileController
    • File Upload GSP
    • Saving the file
      • Grails file upload
      • The save action
      • Validation messages
    • Viewing files
    • Modeling for efficiency
    • Downloading files
    • Summary
  • Querying with criteria
    • Comparing criteria and dynamic finders
    • Using logical operators
    • Querying across relationships
    • Specifying a fetch mode for relationships
    • Criteria reference
    • Logical criteria
    • Setting criteria properties
  • Updating FileController
    • Updating the create file view
    • Handling save
  • Render file versions
  • Fix file download
  • Summary
  • Chapter 9: Services
    • Introducing services
      • Dependency injection
      • Service scope
    • Implementing FileService
    • Summary
  • Chapter 10: Managing Content through Tagging
    • Add basic tagging
      • Tagging domain model
        • The Tag class
        • The Tagger class
      • Tagging a message
      • Tagging a file
        • GORM inheritance
        • Taggable superclass
        • Polymorphic queries
      • Exposing tagging to the users
        • Add the Tags input field
        • Add multiple tags to Taggable
        • Saving the users tags
        • Displaying tags
    • Customize the home page
      • Introducing templates
      • Passing data to a template
        • Render a map
        • Render an object
        • Render a collection
      • Template namespace
      • Create the message and file templates
      • User tags
        • User to tag relationship
        • User ProfileController
        • The myTags form
      • Personalizing the home page
        • Content service
        • Update the HomeController
        • Update the home page
    • All Messages and Files
    • Summary
  • Chapter 11: AJAX and RIA Frameworks
    • Edit tags inline
      • The remoteLink tag
      • The formRemote tag
      • Taggable controller
      • Tag views
      • Tagging domain changes
      • Include the Prototype library
      • Try it out
    • Auto-complete tags
      • Installing the RichUI
      • Implement the auto-complete
        • Suggest tags action
        • RichUI autoComplete widget
    • Introducing tag clouds
      • RichUI tag cloud component
      • Fetch the tag cloud map
      • Filter by tags
      • Rendering the tag cloud
    • Summary
  • Chapter 12: Searching, RSS, and REST Services
    • Searching
      • Make our objects searchable
      • Integrate searching
        • Site-wide search
        • Create the search controller
        • View the search results
        • Update the templates
      • More searching
    • RSS
      • A note about builders
      • Create the RSS feed
      • Remove authorization check
    • REST services
      • REST overview
      • URL mapping
        • Mapping to variables
        • Mapping to HTTP response codes
        • Mapping to HTTP methods
        • REST service mappings
        • Mapping to wildcards
        • Applying constraints
        • Our Message API mapping
      • Implementing the RESTful controller
        • Retrieving messages
        • Creating new messages
      • Authentication for REST API
      • A test script
    • Summary
  • Chapter 13: Build Your Own Plug-in
    • The tagger plug-in
      • Extract the tagging code
      • Accessing plug-in templates through Tag Libraries
      • Calling tags from controllers
      • Current limitations
      • Packaging a plug-in
    • Using plug-in events
      • Grails plug-in lifecycle events
        • doWithSpring
        • doWithWebDescriptor
        • doWithApplicationContext
        • doWithDynamicMethods
        • onChange and onConfigChange
      • Inspecting Grails artifacts
        • The GrailsApplication class
        • Find Taggable domain classes
      • Re-modeling tag relationships
      • Adding Taggable behavior
        • Groovy MetaClass
        • Getting the home page working
        • Items of Interest
        • Create messages and files
        • Update tags
        • List messages and files
        • RSS
    • Summary
  • Chapter 14: Deployment and the Real World
    • Set up the environment
      • Install MySQL
      • Install Tomcat
    • Configure Grails
      • Set up the DataSource
        • DataSource configuration
        • Environmentally aware
        • Database management
        • Update your DB configuration
        • Control the bootstrap
      • Package the WAR file
      • Deploy
    • Hosting options
    • Next steps
      • Java Hibernate classes with GORM
      • Integrating with other presentation frameworks
      • Data migration
    • Summary

Jon Dickinson

Jon Dickinson is the principal consultant and founder of Accolade Consulting Ltd. (http://www.accolade-consulting.co.uk) and can be contacted at jon@accolade-consulting.co.uk. He specializes in developing web applications on the Java platform to meet the goals of users in the simplest and least obtrusive way possible.

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


Errata

- 1 submitted: last submission 10 Sep 2012

page 38 Typo 04 Aug 09
First line under "Create message view"<br />"mesage"<br />should be "message"
 
page 100 Code 25 Aug 09
In the highlighted code to be added to the update method of the UserController, the<br />code reads:<br />userInstance.password = new Sha1Hash(user.password).toHex()<br />Should read "userInstance.password = new Sha1Hash(userInstance.password).toHex()"<br />
 
page 105 Typo 09 Jun 09
"Remember that the principle is the username...".<br />Should be "Remember that the principal is the username...".<br />
 

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Grails 1.1 Web Application Development +    Java EE 5 Development using GlassFish Application Server =
50% Off
the second eBook
Price for both: $28.50

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Understand the relationship between Grails and the Groovy scripting language
  • Learn enough about Groovy to get you writing your first Grails applications
  • Use the built-in AJAX support to enhance user interaction and create slick user interfaces with the RichUI plug-in
  • Develop and use a REST service interface and provide an API through REST
  • Handle file upload and versioning allowing users to share files
  • Use Grails scaffolding to generate a user interface to allow management of users and roles within the application.
  • Secure your application with the JSecurity plug-in and use plug-ins to solve common problems
  • Reduce object persistence issues using Grails Object-Relational Mapper
  • Create your own Grails plug-in for tagging to limit the amount of data that is displayed on your home page
  • Get to grips with automated testing to write functional tests that drive the application
  • Expose your application to other developers with a RESTful API

In Detail

Web development is tricky—even a simple web application has a number of context changes ready to trip up the unwary. Grails takes the everyday pain out of web application development, allowing us to focus on delivering real application logic and create seamless experiences that will address the needs of our users. This book will take the pain out of Grails by showing you exactly how to build a web application with a minimum of fuss.

With this book, even if you are new to Grails, you will be up and running before you know it. You will be able to code faster and your code will be better. This clear and concise book is packed with examples and clear instructions to help you build your first Grails application and gives you the skills to speed up your application development by adding a different angle for learning about the topic. After a brief introduction to the dynamic JVM-based Groovy programming language, which teaches you enough about Groovy to understand the relationship between Grails and the Groovy scripting language, it shows how to use Grails and a number of key plug-ins to deliver valuable web applications. It also takes you through creating, developing, testing, and deploying an example team collaboration application in Grails.

Using an incremental and iterative approach you will learn how to build a basic web application with secure authentication and different levels of authorization. You will learn how to handle file upload allowing users to share files. Some advanced features of object-oriented persistence will be introduced through adding tags for messages and files to giving users a robust categorization system.

You will then build on the basic application to enhance the user experience through AJAX and the RichUI plug-in. You will take a further step into the world of Web 2.0 by adding an RSS feed and a REST service to the application. Once the entire application is up and running, you will learn how to create your own plug-in for tagging. Finally, you will learn how to deploy this application to a production environment.

Create a real-world web application with Grails, taking a step-by-step approach to deliver a team collaboration portal.

Approach

This book is a guide to building a rich web application using Grails. The approach taken for building the application is incremental and iterative; each chapter will produce a working addition to the application, or iterate over existing features, as well as introduce and carefully explain the new part of the Grails framework used. The book does not go into exhaustive descriptions of every detail of Grails. While there is a lot of code in the book, there are very few large code listings. As you will find, it is not necessary to write reams of code to get results using Groovy and Grails.

Who this book is for

This book is aimed at Java web developers looking for ways to build web applications quickly, and wanting to find out how it's done quickly. If you are frustrated with integrating the many different frameworks that are available for web development and want to get on with building slick web applications for your users, then this book is for you. Grails is built on the Groovy language, but experience in Groovy is not required, as you will learn enough about Groovy to understand how to use Grails.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software