Grails Cookbook - A collection of tutorials and examples

Grails Tutorial for Beginners - HQL Queries (executeQuery and executeUpdate)

This Grails tutorial will teach the basics of using HQL. Grails supports dynamic finders which makes it convenient to perform simple database queries. But for more complex cases, Grails provides both Criteria API and HQL. This tutorial will focus on the latter.

Grails Tutorial for Beginners - Criteria API

This tutorial will show how to use Criteria API to search data from the database. Criteria is a powerful API and an elegant alternative to HQL.

Grails Tutorial for Beginners - Grails Service Layer

This tutorial will discuss the importance of the service layer in Grails and how to work with it. It also explains transaction management and how to utilize it.

Grails Tutorial for Beginners - Scaffolding

Scaffolding is a popular feature of web frameworks where a programmer can quickly create working components of a system to handle data manipulation. Code to handle create, read, update and delete operations (CRUD) for a specific table can be implemented or generated within several minutes only through the use of code generators or other shortcuts.

Grails Tutorial for Beginners - Display Data from the Database

The most common thing we want to do in Grails is to read data from the database and display it to the user. This post is a simple walk-through on how to accomplish this.

Grails Tutorial for Beginners - Form Submission and Saving Data to the Database

HTML Forms are usually used to gather data from users. This post will show how to make use of forms to save data to the database.
This example will render a form that looks like this:
And on click of save, will save the data to the person table.

Grails Tutorial for Beginners - Introduction to GORM

GORM is half the reason why I use Grails as my default choice in implementing new projects. Using it just makes implementation of business logic a breeze. Working with a database becomes so easy.
GORM is Grails' object relational mapping (ORM) implementation, which sits on top of the very popular Hibernate framework. If you are familiar with Hibernate, then you can pick up GORM in an instant. Don't worry otherwise as GORM is straightforward and easy to learn.

Grails Tutorial for Beginners - Layout Templates

When coding screens, there are many elements that are common and repetitive. Usually the header, footer, and sidebars stays the same and only the content at the middle of the screen that change. The best approach is to have your GSP page contain only the specific business content, and have the repeating content re-factored outside. Grails supports layout templates for this particular purpose.

Grails Tutorial for Beginners - Basic Groovy Server Pages (GSP)

Groovy Server Pages (or GSP) is the default presentation technology for rendering views in Grails. It is very similar to JSP where you can easily combine static and dynamic contents in your output. The Grails framework have made it very easy to use yet powerful enough for most use cases.

Grails Tutorial for Beginners - Starting with Controllers

When learning Grails or any other framework, I recommend to study each components separately first. Rather than tackling multiple topics at the same time. For Grails beginners, I recommend to start with controllers. This is one of the simplest to understand and you can see results right away!