HomeTechnologyRapid Web Development with Grails

Rapid Web Development with Grails

Grails Features

Grails is a request-based, MVC, open-source web development framework. More than just that, though, it is a complete development platform in which everything runs on top of the robust Java and Java EE platforms as illustrated. It leverages the existing popular Java frameworks.

Convention over Configuration

Rather than configuration, Grails gives precedence to the convention. Convention over configuration, in simple terms, means writing configuration code only when you deviate from the convention. These ingenious conventions correspond to the directory structure; Grails brings into play the name and location of the files instead of relying on explicit configuration via the wiring of XML configuration files. This means if you create a class following the Grails conventions, Grails will wire it into Spring or treat it as a Hibernate entity. If you create a new domain class called Book, Grails will automatically create a table called to book in the database. By using the convention-over-configuration paradigm, Grails can envisage a component from its name and its location in the directory structure. One immediate consequence of this, other than speeding up application development, is that you have to configure a particular aspect of a component only when that configuration deviates from the standard.


The Grails scaffolding generates an application’s CRUD functionality from the domain classes, at either runtime or development time. The generated application consists of the controller and GSP views associated with the domain class. The scaffolding also generates the database schema, including tables for each of the domain classes.

Object-Relational Mapping

Grails includes a powerful object-relational mapping (ORM) framework called Grails Object Relational Mapping (GORM). Like most ORM frameworks, GORM maps objects to relational databases; but unlike other ORM frameworks, GORM is based on a dynamic language. Therefore GORM can inject the CRUD methods right into the class without having to implement them or inherit them from persistent superclasses.


Instead of providing out-of-the-box solutions for every possible requirement, Grails offers a plug-in architecture, and you can find plug-ins for a plethora of functionalities.

Unit Testing

For improving the quality of the deliverables, Grails provides unit tests, integration tests, and functional tests for automating the web interface

Bookstore Application

You will be learning to leverage the Grails conventions and scaffolding to create a simple but functional version of the bookstore application. This initial version of the application will not be production-ready, however; the objective of this application is to show you how, with scaffolding, you can render a CRUD web application with almost no code other than your domain class code. In addition, Grails will generate a database schema and populate a database with the schema when the application is run

Running the Application

At this point, you have a functional application that you can run and access through a web browser. It does not do much yet, but running it now will enable you to get instant feedback as you add domain and controller classes.

Creating the Controller

A controller handles requests and creates or prepares responses. A controller can generate the response directly or delegate to a view. To create a controller class, use the Grails create-controller target. This creates a new Grails controller class in the grails-app/controllers directory, as well as the unit test for the controller class in test/unit. It also creates a grails-app/views/ directory if it doesn’t exist already.

Creating a Domain Class

At this point, the application we created doesn’t really do anything; it just renders a simple textual response. We will move on by creating a domain class. To create a domain class, use the Grails create-domain-class target. This creates a new Grails domain class in the grails-app/domain directory, as well as a unit test for the domain class in test/unit.


In this chapter, you learned that Grails is a rapid web development framework that combines the best of Java open-source, conventions, the Groovy dynamic language, and the power of the Java platform. You saw how easy it is to develop a fully functional application using Grails scaffolding to do most of the work. You used static scaffolding as a learning tool, generating the controller and views for one domain class (Book). Then you navigated through the controller and saw that all the work in the controller is done in the actions. Then you learned the code for each action responsible for the corresponding view. Finally, you navigated through the views and saw how the views take advantage of the Grails tag libraries to promote a clean separation of concerns



Please enter your comment!
Please enter your name here

Most Recent

Category List