tags:

views:

26

answers:

2

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?

A: 

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" />
proflux
+1  A: 

Are you sure the layout isn't applied? I'm using Grails 1.3.2 and I thought the layout wasn't applied, however it actually was the lack of a model and security tags in the layout after a 404.

If your layout content is derived from such things being available, try a "Hello world" first to see if it shows up.

wwwclaes