5.5.1 Events and Auto Timestamping ........................................................................................................................ 52
5.5.2 Custom ORM Mapping ..................................................................................................................................... 54
5.5.2.1 Table and Column Names .......................................................................................................................... 54
5.5.2.2 Caching Strategy ....................................................................................................................................... 57
5.5.2.3 Inheritance Strategies................................................................................................................................ 58
5.5.2.4 Custom Database Identity .......................................................................................................................... 59
5.5.2.5 Composite Primary Keys............................................................................................................................. 59
5.5.2.6 Database Indices....................................................................................................................................... 60
5.5.2.7 Optimistic Locking and Versioning............................................................................................................... 60
5.5.2.8 Eager and Lazy Fetching ............................................................................................................................ 60
5.5.2.9 Custom Cascade Behaviour ........................................................................................................................ 61
5.5.2.10 Custom Hibernate Types .......................................................................................................................... 62
5.5.3 Default Sort Order........................................................................................................................................... 63
5.6 Programmatic Transactions ................................................................................................................................... 63
5.7 GORM and Constraints .......................................................................................................................................... 64
6. The Web Layer ......................................................................................................................................................... 67
6.1 Controllers ........................................................................................................................................................... 67
6.1.1 Understanding Controllers and Actions.............................................................................................................. 67
6.1.2 Controllers and Scopes .................................................................................................................................... 68
6.1.3 Models and Views ........................................................................................................................................... 69
6.1.4 Redirects and Chaining .................................................................................................................................... 71
6.1.5 Controller Interceptors .................................................................................................................................... 72
6.1.6 Data Binding................................................................................................................................................... 74
6.1.7 XML and JSON Responses................................................................................................................................ 77
6.1.8 Uploading Files ............................................................................................................................................... 79
6.1.9 Command Objects........................................................................................................................................... 80
6.1.10 Handling Duplicate Form Submissions............................................................................................................. 81
6.2 Groovy Server Pages............................................................................................................................................. 82
6.2.1 GSP Basics ..................................................................................................................................................... 82
6.2.1.1 Variables and Scopes ................................................................................................................................. 83
6.2.1.2 Logic and Iteration .................................................................................................................................... 83
6.2.1.3 Page Directives ......................................................................................................................................... 84
6.2.1.4 Expressions............................................................................................................................................... 84
6.2.2 GSP Tags ....................................................................................................................................................... 85
6.2.2.1 Variables and Scopes ................................................................................................................................. 85
6.2.2.2 Logic and Iteration .................................................................................................................................... 86
6.2.2.3 Search and Filtering................................................................................................................................... 86
6.2.2.4 Links and Resources .................................................................................................................................. 87
6.2.2.5 Forms and Fields ....................................................................................................................................... 87
6.2.2.6 Tags as Method Calls ................................................................................................................................. 88
6.2.3 Views and Templates ...................................................................................................................................... 88
6.2.4 Layouts with Sitemesh..................................................................................................................................... 90
6.2.5 Sitemesh Content Blocks ................................................................................................................................. 92
6.3 Tag Libraries ........................................................................................................................................................ 93
6.3.1 Variables and Scopes ...................................................................................................................................... 93
6.3.2 Simple Tags.................................................................................................................................................... 94
6.3.3 Logical Tags ................................................................................................................................................... 94
6.3.4 Iterative Tags ................................................................................................................................................. 95
6.3.5 Tag Namespaces............................................................................................................................................. 96
6.3.6 Using JSP Tag Libraries ................................................................................................................................... 96
6.4 URL Mappings ...................................................................................................................................................... 96
6.4.1 Mapping to Controllers and Actions .................................................................................................................. 97
6.4.2 Embedded Variables........................................................................................................................................ 97
6.4.3 Mapping to Views............................................................................................................................................ 99
6.4.4 Mapping to Response Codes ............................................................................................................................ 99
6.4.5 Mapping to HTTP methods .............................................................................................................................100
6.4.6 Mapping Wildcards......................................................................................................................................... 100
6.4.7 Automatic Link Re-Writing .............................................................................................................................. 101
6.4.8 Applying Constraints....................................................................................................................................... 101
6.5 Web Flow............................................................................................................................................................ 102
6.5.1 Start and End States ...................................................................................................................................... 102
6.5.2 Action States and View States .........................................................................................................................103
6.5.3 Flow Execution Events....................................................................................................................................104
6.5.4 Flow Scopes .................................................................................................................................................. 105
6.5.5 Data Binding and Validation ............................................................................................................................ 107
6.5.6 Subflows and Conversations ...........................................................................................................................108
6.6 Filters ................................................................................................................................................................. 109
6.6.1 Applying Filters .............................................................................................................................................. 109
6.6.2 Filter Types ................................................................................................................................................... 110
6.6.3 Variables and Scopes .....................................................................................................................................110
The Grails Framework - Reference Documentation
3