Grails “render” renders the template

倖福魔咒の 提交于 2019-12-03 02:50:55

Resolved: Adding contentType results in the template not being rendered:

render text: "Name: ${person.name}", contentType: "text/plain"

Make your client side javascript code handle a JSON respond and render your response with:

render [text:"Name: ${person.name}"] as JSON

You might be getting burnt by the 'layout-by-convention' feature in Grails. If your layout name matches the controller name prefix, for example, Grails will apply the layout to every view managed by that controller. Unfortunately, it even applies to text and templates. There are currently a few JIRAs logged regarding this (see http://jira.grails.org/browse/GRAILS-7624 for example). I got burnt by this today. I resolved it by simply renaming my layout gsp such that it doesn't match any controller name. My layout was initially named 'storefront.gsp' and I have a controller named StorefrontController. I renamed the layout to 'public.gsp'.

We've found that explicitly returning false from the action fixes this.

I believe doing render foo as JSON returns false implicitly.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!