4
votes

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?

3
This also seems to be a problem with Grails 2.1.0... - Tristan
@Tristan, were you ever able to find a fix for your issue? - Igor
@Igor I don't think I did (and ended up ditching Grails) for the project. - Tristan

3 Answers

5
votes

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" />
2
votes

Another thing to look for is the sitemesh.xml configuration file. Sitemesh is turned on/off depending on the content-type of the response, and this file declares the content-types values that site-mesh will process. In my case, an entry for text/html;charset=UTF-8 was not enough for responses with type text/html to be processed.

1
votes

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.