404 with Grails
Grails allows you to specify a custom 404 page simply using the UrlMappings.groovy class:
This allows you to direct to a controller where you can then forward to a view:
I started off with a simple view using the 'main' layout:
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:
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)
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)