The Grails Framework
Table of contents
1
Introduction
2
Getting Started
3
Upgrading from the previous versions
4
Configuration
5
The Command Line
6
Application Profiles
7
Object Relational Mapping (GORM)
8
The Web Layer
9
Traits
10
REST
11
Asynchronous Programming
12
Validation
13
The Service Layer
14
Static Type Checking And Compilation
15
Testing
16
Building a Successful Application
17
Internationalization
18
Security
19
Plugins
20
Grails and Spring
21
Scaffolding
22
Grails Cache
23
Deployment
24
Contributing to Grails
Quick Reference
(
Quick Reference
)
The Grails Framework
Authors:
The Apache Grails Team
Version:
SNAPSHOT
8.0.0-SNAPSHOT
Table of Contents
1
Introduction
1.1
What's new in Grails 7?
1.1.1
Updated Dependencies
2
Getting Started
2.1
Installation Requirements
2.2
Downloading and Installing
2.3
Creating an Application
2.4
Creating a Simple Web Application with Grails
2.5
Using Interactive Mode
2.6
Getting Set Up in an IDE
2.7
Grails Directory Structure and Convention over Configuration
2.8
Running and Debugging an Application
2.9
Testing an Application
2.10
Deploying an Application
2.11
Supported Jakarta EE Containers
2.12
Creating Artefacts
2.13
Generating an Application
2.14
Development Reloading
3
Upgrading from the previous versions
3.1
Upgrading from Grails 7 to Grails 8
3.2
Upgrading from Grails 7.1 to Grails 7.2
3.3
Upgrading from Grails 7.0 to Grails 7.1
3.4
Upgrading from Grails 6 to Grails 7.0
3.5
Upgrading from Grails 5 to Grails 6
3.6
Upgrading from Grails 4 to Grails 5
3.7
Upgrading from Grails 3.3.x to Grails 4
4
Configuration
4.1
Configuration Types
4.1.1
YML Configuration
4.1.2
External Configuration
4.1.3
Built-in Properties
4.1.4
Logging
4.1.4.1
Logger Names
4.1.4.2
Masking Request Parameters From Stacktrace Logs
4.1.4.3
Logging Full Stack Traces
4.1.4.4
External Configuration File
4.1.5
GORM
4.1.6
Configuring an HTTP proxy
4.2
The Application Class
4.2.1
Executing the Application Class
4.2.2
Customizing the Application Class
4.2.3
The Application LifeCycle
4.3
Environments
4.4
The DataSource
4.4.1
DataSources and Environments
4.4.2
Automatic Database Migration
4.4.3
Transaction-aware DataSource Proxy
4.4.4
Database Console
4.4.5
Multiple Datasources
4.5
Versioning
4.6
Dependency Resolution
5
The Command Line
5.1
Interactive Mode
5.2
Creating Custom Scripts
5.3
Creating Custom Commands
5.4
Creating a Grails Project
5.5
Re-using Grails scripts
5.6
Building with Gradle
5.6.1
Defining Dependencies with Gradle
5.6.2
Working with Gradle Tasks
5.6.3
Grails plugins for Gradle
6
Application Profiles
6.1
Standard Profiles
6.1.1
Web Profile
6.1.2
REST API Profile
6.1.3
Plugin Profile
6.1.4
Web Plugin Profile
6.1.5
REST API Plugin Profile
6.1.6
Profile Profile
6.2
Creating Profiles
6.3
Profile Inheritance
6.4
Publishing Profiles
6.5
Understanding Profiles
6.6
Creating Profile Commands
6.7
Creating Profile Features
7
Object Relational Mapping (GORM)
7.1
Quick Start Guide
7.1.1
Basic CRUD
7.2
Further Reading on GORM
8
The Web Layer
8.1
Controllers
8.1.1
Understanding Controllers and Actions
8.1.2
Controllers and Scopes
8.1.3
Models and Views
8.1.4
Redirects and Chaining
8.1.5
Data Binding
8.1.6
Responding with JSON
8.1.7
More on JSONBuilder
8.1.8
Responding with XML
8.1.9
Uploading Files
8.1.10
Command Objects
8.1.11
Handling Duplicate Form Submissions
8.1.12
Simple Type Converters
8.1.13
Declarative Controller Exception Handling
8.2
Groovy Server Pages
8.2.1
GSP Basics
8.2.1.1
Variables and Scopes
8.2.1.2
Logic and Iteration
8.2.1.3
Page Directives
8.2.1.4
Expressions
8.2.2
GSP Tags
8.2.2.1
Variables and Scopes
8.2.2.2
Logic and Iteration
8.2.2.3
Search and Filtering
8.2.2.4
Links and Resources
8.2.2.5
Forms and Fields
8.2.2.6
Tags as Method Calls
8.2.3
Views and Templates
8.2.4
Layouts
8.2.4.1
Content Blocks
8.2.5
Static Resources
8.2.6
Making Changes to a Deployed Application
8.2.7
Tag Libraries
8.2.7.1
Variables and Scopes
8.2.7.2
Simple Tags
8.2.7.3
Logical Tags
8.2.7.4
Iterative Tags
8.2.7.5
Tag Namespaces
8.2.7.6
Using JSP Tag Libraries
8.2.7.7
Tag return value
8.3
Fields Plugin
8.3.1
Installation
8.3.2
Usage
8.3.3
Customizing Field Rendering
8.3.4
Embedded Properties
8.3.5
Themes
8.3.6
Including Templates in Plugins
8.3.7
Performance
8.3.8
Scaffolding
8.4
JSON Views
8.4.1
Installation
8.4.2
Templates
8.4.3
Rendering Domain Classes
8.4.4
JSON View API
8.4.5
Model Naming
8.4.6
Content Negotiation
8.4.7
HAL Support
8.4.8
JSON API Support
8.4.9
The JsonTemplateEngine
8.4.10
Static Compilation
8.4.11
Testing
8.4.12
Plugin Support
8.4.13
Configuration
8.4.14
Custom Converters
8.4.15
IntelliJ Support
8.4.16
Debugging Views
8.5
Markup Views
8.5.1
Installation
8.5.2
Markup View API
8.5.3
Configuration
8.6
URL Mappings
8.6.1
Mapping to Controllers and Actions
8.6.2
Mapping to REST resources
8.6.3
Redirects In URL Mappings
8.6.4
Embedded Variables
8.6.5
Mapping to Views
8.6.6
Mapping to Response Codes
8.6.7
Mapping to HTTP methods
8.6.8
Mapping Wildcards
8.6.9
Automatic Link Re-Writing
8.6.10
Applying Constraints
8.6.11
Named URL Mappings
8.6.12
Customizing URL Formats
8.6.13
Namespaced Controllers
8.7
CORS
8.8
Interceptors
8.8.1
Defining Interceptors
8.8.2
Matching Requests with Interceptors
8.8.3
Ordering Interceptor Execution
8.9
Content Negotiation
9
Traits
9.1
Traits Provided by Grails
9.1.1
WebAttributes Trait Example
10
REST
10.1
Domain classes as REST resources
10.2
Mapping to REST resources
10.3
Linking to REST resources from GSP pages
10.4
Versioning REST resources
10.5
Implementing REST controllers
10.5.1
Extending the RestfulController super class
10.5.2
Implementing REST Controllers Step by Step
10.5.3
Generating a REST controller using scaffolding
10.6
Calling REST Services with HttpClient
10.7
The REST Profile
10.8
JSON Views
10.8.1
Getting Started
10.8.2
Creating JSON Views
10.8.3
JSON View Templates
10.8.4
Rendering Domain Classes with JSON Views
10.8.5
JSON Views by Convention
10.9
Customizing Response Rendering
10.9.1
Customizing the Default Renderers
10.9.2
Implementing a Custom Renderer
10.9.3
Using GSP to Customize Rendering
10.10
Hypermedia as the Engine of Application State
10.10.1
HAL Support
10.10.2
Atom Support
10.10.3
Vnd.Error Support
10.11
Customizing Binding of Resources
10.12
RSS and Atom
11
Asynchronous Programming
11.1
Promises
11.2
Events
11.2.1
Event Publishing
11.2.2
Subscribing to Events
11.2.3
Reactor Spring Annotations
11.2.4
Events from GORM
11.2.5
Events from Spring
11.2.6
Configure the Default Event Bus
11.3
Asynchronous GORM
11.4
RxJava Support
11.4.1
Server Sent Events
11.4.2
RxGORM
11.5
Asynchronous Request Handling
11.6
Servlet 3.0 Async
12
Validation
12.1
Declaring Constraints
12.2
Validating Constraints
12.3
Sharing Constraints Between Classes
12.4
Validation on the Client
12.5
Validation and Internationalization
12.6
Applying Validation to Other Classes
13
The Service Layer
13.1
Declarative Transactions
13.1.1
Transactions and Multi-DataSources
13.1.2
Transactions Rollback and the Session
13.2
Scoped Services
13.3
Dependency Injection and Services
14
Static Type Checking And Compilation
14.1
The GrailsCompileStatic Annotation
14.2
The GrailsTypeChecked Annotation
15
Testing
15.1
Generating Tests
15.2
Running Tests
15.2.1
With Grails CLI
15.2.2
With Gradle
15.3
Unit Testing
15.3.1
Installation
15.3.2
Upgrading From The Mixin Framework
15.3.3
Unit Testing Controllers
15.3.4
Unit Testing Domain Classes
15.3.5
Unit Testing Services
15.3.6
Unit Testing Tag Libraries
15.3.7
Unit Testing Interceptors
15.3.8
Unit Testing Url Mappings
15.3.9
Annotations
15.3.10
Useful Properties
15.4
Integration Testing
15.5
Functional Testing
15.6
Custom Test Phases
16
Building a Successful Application
16.1
Code Analysis and Styling for Groovy
17
Internationalization
17.1
Understanding Message Bundles
17.2
Changing Locales
17.3
Reading Messages
17.4
Scaffolding and i18n
18
Security
18.1
Securing Against Attacks
18.2
Cross Site Scripting (XSS) Prevention
18.3
Encoding and Decoding Objects
18.4
Authentication
18.5
Security Plugins
18.5.1
Spring Security
19
Plugins
19.1
Creating and Installing Plugins
19.2
Plugin Repositories
19.3
Providing Basic Artefacts
19.4
Evaluating Conventions
19.5
Hooking into Runtime Configuration
19.6
Adding Methods at Compile Time
19.7
Adding Dynamic Methods at Runtime
19.8
Participating in Auto Reload Events
19.9
Understanding Plugin Load Order
19.10
The Artefact API
19.10.1
Asking About Available Artefacts
19.10.2
Adding Your Own Artefact Types
20
Grails and Spring
20.1
Configuring Additional Beans
20.2
Runtime Spring with the Beans DSL
20.3
The BeanBuilder DSL Explained
20.4
Property Placeholder Configuration
20.5
Property Override Configuration
20.6
Spring Boot Actuators
21
Scaffolding
22
Grails Cache
22.1
Usage
22.1.1
Configuration
22.1.2
Cache Annotations
22.1.2.1
Unit Testing
22.1.3
The CacheManager
22.2
Caching Tags
22.3
The Cache Admin Service
22.3.1
Clearing Caches
22.4
Implementation Details
23
Deployment
23.1
Standalone
23.2
Container Deployment (e.g. Tomcat)
23.3
Deployment Configuration Tasks
24
Contributing to Grails
Quick Reference
(
hide
)
API
Groovy Doc
Command Line
Usage
assemble
bootRun
bug-report
clean
compile
console
create-app
create-command
create-controller
create-domain-class
create-functional-test
create-hibernate-cfg-xml
create-integration-test
create-interceptor
create-job
create-plugin
create-profile
create-restapi
create-script
create-service
create-taglib
create-unit-test
create-web-plugin
dependency-report
generate-all
generate-controller
generate-views
help
install-templates
list-features
list-plugins
list-profiles
package-plugin
package
plugin-info
profile-info
run-app
run-command
run-script
schema-export
shell
stats
stop-app
test-app
war
Configuration
Application Properties
Constraints
Usage
attributes
bindable
blank
creditCard
email
inList
matches
max
maxSize
min
minSize
notEqual
nullable
range
scale
size
unique
url
validator
widget
Controllers
Usage
actionName
allowedMethods
bindData
chain
controllerName
defaultAction
errors
flash
forward
grailsApplication
hasErrors
header
namespace
params
redirect
render
request
respond
response
responseFormats
scope
servletContext
session
withForm
withFormat
Database Mapping
Usage
autoImport
autoTimestamp
batchSize
cache
cascade
column
comment
discriminator
dynamicInsert
dynamicUpdate
fetch
id
ignoreNotFound
indexColumn
insertable
joinTable
lazy
order
sort
table
type
updatable
version
Domain Classes
Usage
addTo
attach
belongsTo
clearErrors
constraints
count
countBy
createCriteria
delete
discard
embedded
errors
executeQuery
executeUpdate
exists
fetchMode
find
findAll
findAllBy
findAllWhere
findBy
findOrCreateBy
findOrCreateWhere
findOrSaveBy
findOrSaveWhere
findWhere
first
get
getAll
getDirtyPropertyNames
getPersistentValue
hasErrors
hasMany
hasOne
ident
instanceOf
isAttached
isDirty
last
list
listOrderBy
load
lock
mapWith
mappedBy
mapping
merge
namedQueries
properties
read
refresh
removeFrom
save
transients
validate
where
whereAny
withCriteria
withNewSession
withSession
withTransaction
Plug-ins
Usage
URL mappings
codecs
controllers
core
dataSource
domainClasses
hibernate
i18n
logging
scaffolding
services
servlets
Services
Usage
scope
Servlet API
request
response
servletContext
session
Tag Libraries
Usage
actionName
controllerName
flash
pageScope
params
request
response
servletContext
session
Tags - Cache
block
render
Tags - Fields
all
display
displayWidget
field
input
table
widget
with
Tags - GSP
actionSubmit
actionSubmitImage
applyLayout
checkBox
collect
cookie
country
countrySelect
createLink
createLinkTo
currencySelect
datePicker
each
eachError
else
elseif
external
field
fieldError
fieldValue
findAll
flashMessages
form
formActionSubmit
formatBoolean
formatDate
formatNumber
grep
hasErrors
header
hiddenField
if
img
include
isAvailable
isNotAvailable
javascript
join
layoutBody
layoutHead
layoutTitle
link
localeSelect
message
meta
pageProperty
paginate
passwordField
radio
radioGroup
render
renderErrors
resource
select
set
sortableColumn
submitButton
textArea
textField
timeZoneSelect
unless
uploadForm
while
Versions
Grails BOM Hibernate5
Grails BOM Micronaut
Grails BOM