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 = {
render(view:'/error')
}

def notFound = {
render(view:'/notFound')
}
}

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

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">
<body>
Page not found!
</body>
</g:applyLayout>

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

Slow, Buffering, Stuttering Udemy Video

Intellij tip - Joining multiple lines into one

Looking for IT work in Australia? JobReel.com.au!