Filters

Filters allow us to hook into, or intercept, the processing of a request. There are interceptors for before, after, and afterView. There are many uses for filters, and you can have as many filters as you need in an application. In our case, we’ll use a filter to determine whether a user is logged in when they try to access a “secure” page.

This must be sounding like a broken record (does anyone remember what that is?), but Grails makes implementing filters a snap. Create a Groovy class with a name ending in Filters, and place it in the grails-app/conf directory. In this class, define a code block called filters, and then include individual filters as if they were methods. Each filter (method) can take named parameters for controller ...

Get Grails 2: A Quick-Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.