404 with Grails

Grails allows you to specify a custom 404 page simply using the UrlMappings.groovy class:
class UrlMappings {
static mappings = {
"500"(controller:"errors", action:"serverError")
"404"(controller:"errors", action:"notFound")

This allows you to direct to a controller where you can then forward to a view:
class ErrorsController {
def serverError = {

def notFound = {

I started off with a simple view using the 'main' layout:
<meta name="layout" content="main" />
Page not found!

But for some reason, the layout does not get applied. I haven't dug to the bottom of this yet, but I have found a work-around:
<g:applyLayout name="main">
Page not found!

Now the layout is applied and the page looks like I would expect.

The error page for '500' is fine, it only seems to affect the 404 page.

(Grails 1.0-RC1  & Grails 1.0-RC2)

Popular posts from this blog

Using the Crystal Reports Java API to generate PDF

No Scope registered for scope request

Using Selenium WebDriver to select JSF/PrimeFaces selectOneMenu options