Grails layouts do not apply to 404 UrlMapping

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

When this action is usually performed ( http: // localhost / list / index ), then both the layout file and the fragment are applied, and it looks correct. However, when accessed through rule 404 in the UrlMapping class, it is "404" (controller: "list" , action: "index") - the layout file is not used, and only a fragment is displayed.

Does anyone know why this is happening, and is there some way I can display a normal layout for 404 (or another) error display?

+4
source share
3 answers

Are you sure the layout is not applicable? I am using Grails 1.3.2, and I thought that the layout was not applied, however in reality it was the absence of the model and security tags in the layout after 404.

If your layout content is derived from such accessible things, first try β€œHello World” to see if it appears.

+1
source

I know some time ago, it was a bug in the SiteMesh version that Grails used. There is work in which you can wrap your error pages in:

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

Instead of the usual:

 <meta name="layout" content="main" /> 
+5
source

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

+2
source

Source: https://habr.com/ru/post/1314034/


All Articles