Grails Cookbook - A collection of tutorials and examples

Grails Domain count and countBy Examples

This will show how to use a Grails domain's count and countBy methods.

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 chained select - load data on one dropdown box depending on another

This tutorial will show how to create two select boxes where the second select box's items are affected by the value of the first one. Developers encounters this commonly and it is also called chained select. An example is selecting a country, followed by selecting a state. The choices for states should be based on which country was selected.

How to make Grails use an external properties file for datasource configuration

This tutorial will show how to use an external properties file to configure the datasource of a Grails application. Hardcoding database properties should only be limited for development purposes. But when deploying an application to another environment (E.g. test, UAT, production), it is usually convenient to be able to change things freely.

Grails render images on the fly in GSP

This tutorial will show how to generate PNG images on the fly and display inside a GSP. This can serve as a basis on how to create a more complex behavior. For example, creating report graphs for display in your applications.

Grails Forum Application

This tutorial will show how to implement a simple forum application using Grails. Complete source code will be shown at the end

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 Example - Upload Excel Data File To Database

This example will show how to handle Excel upload and save each row in the file as a record in the database.

Grails Spring Security Core Plugin - Registering Callback Closures

I was searching for a way to hook business logic after successful user login while using Spring Security Core plugin. The simplest way to do this is to register callback closures. It let's you hook your custom code inside Config.groovy after certain Spring Security events.