Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails layouts not applied on a 404 UrlMapping

Tags:

grails

In a Grails 1.3.1 app, I want 404 errors to cause the render the main index action of the "list" controller. This controller uses a conventional layout file in the layouts directory (views/layouts/list.gsp), which then uses the included snippet for that action (views/list/index.gsp).

When this action is accessed normally (http://localhost/list/index), then both the layout file and the snippet are applied, and it looks correct. However, when accessed via a 404 rule in the UrlMapping class -- "404"(controller: "list", action: "index") -- the layout file isn't used, and only the snippet is displayed.

Does anyone know why this happens, and if there's any way to get the conventional layout to display for a 404 (or other) error mapping?

like image 919
Kaleb Brasee Avatar asked Feb 26 '23 18:02

Kaleb Brasee


1 Answers

I know a while back this was a bug in the version of SiteMesh Grails was using. There is a work around where you can wrap your error pages in:

<g:applyLayout name="main">  
</g:applyLayout>

Instead of using the usual:

<meta name="layout" content="main" />
like image 135
proflux Avatar answered Mar 07 '23 13:03

proflux