Grails layouts not applied on a 404 UrlMapping
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 layou开发者_StackOverflow社区ts 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?
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" />
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.
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.
精彩评论