Grails“回应”从.war文件启动时呈现错误的视图 [英] Grails "respond" renders the wrong view when launched from .war file
问题描述
Grails应用程序使用新的RESTful响应功能自动生成很多(来自标准Grails 2.3.0脚手架)代码。例如,索引方法通常如下所示:
def index(整数最大值){
params.max = Math.min(max?:10,100)
响应Alpha.list(params),model:[alphaInstanceCount:Alpha.count()]
}
当应用程序以grails run-app运行时,这种方式完全正常,但应用程序打包为.war并在内部启动时失败一个非嵌入式servlet容器。
它适用于所使用的第一个控制器/视图组合,但对于随后的视图文件夹使用渲染的第一个视图的视图文件夹。例如,如果我们首先尝试 / alpha / index
,然后 / alpha / index
会正常工作,但是 / beta / index
会使用 /alpha/index.gsp
用于渲染(而不是预期的 /beta/index.gsp
)。
如果然而,我改变了方法:
$ b $ pre $ code def index(整数最大值){
params.max = Math。 min(max?:10,100)
render(view:'index',model:[alphaInstanceList:Alpha.list(params),alphaInstanceCount:Alpha.count()])
}
那么它在两个部署选项中都可以正常工作。
我为一些.gsp-s添加了一些调试代码,以输出 $ {this.getGroovyPageFileName()}
, $ {controllerName}
和 $ {actionName}
。
这表明虽然控制器和动作名称总是预期的那些,在第一个之后呈现的视图上使用的视图仍然是视图使用例如,对于 / alpha / index
的初始调用将控制器设置为<$ <
$ b
c $ c> alpha ,作为 index
的操作,并且视图为 / WEB-INF / grails-app / views / alpha / index.gsp
,但是 / beta / index
的 后继调用有控制器为 beta
,查看为 index
,但查看为 / WEB-INF / grails- app / views / alpha / index.gsp
( 在这里记下错误的alpha )。随后调用 alpha
仍然可以。
如果我们已经开始使用beta版,然后转到alpha版, ( beta
没有问题, alpha
已被破坏)。
我试着在JPDA下面运行它,但是当我的IDE似乎连接它时,它并没有实际触及任何断点(可能与此无关)。
I使用Grails 2.3.0,JDK 1.6和Tomcat7。
没有什么不好,我可以在日志中看到。
任何想法可能是什么问题,甚至只是如何进行调试呢?
http://goo.gl/aFKYYb < ; - grails应用程序
http://goo.gl/aDP6Lx < - .war file
可能的Grails缺陷(尽管它们无法重现):
http://jira.grails.org/browse/ GRAILS-10614
我做了一个install-templates,并且正在修改脚手架模板作为解决方案。
编辑 - 是,已确认;我忘记更新此响应,但升级到2.3.1解决了问题,根据链接的缺陷。
A Grails application has a lot of auto-generated (from standard Grails 2.3.0 scaffolding) code using the new RESTful "respond" feature. For example, the index methods generally look like this:
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
respond Alpha.list(params), model:[alphaInstanceCount: Alpha.count()]
}
This works completely fine when the application is run as "grails run-app" however fails when the application is packaged as a .war and launched that way inside a non-embedded servlet container.
It works for the first controller/view combination used, but for subsequent ones uses the view folder of the first view rendered. E.g., if we try /alpha/index
first, and then afterwards /beta/index
then the /alpha/index
will work fine, but /beta/index
will use /alpha/index.gsp
for rendering (instead of the expected /beta/index.gsp
).
If, however, I change the method to:
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
render(view: 'index', model:[alphaInstanceList: Alpha.list(params), alphaInstanceCount: Alpha.count()])
}
then it works fine in both deployment options.
I added some debug code to some of the .gsp-s to output ${this.getGroovyPageFileName()}
, ${controllerName}
and ${actionName}
.
That shows that while the controller and action names are always the expected ones, the view used on views rendered after the first one remains the view used on the first one.
For example, the initial invocation for /alpha/index
has controller as alpha
, action as index
, and view as /WEB-INF/grails-app/views/alpha/index.gsp
, however the consequent invocation of /beta/index
has controller as beta
, view as index
, but view as /WEB-INF/grails-app/views/alpha/index.gsp
(note the wrong "alpha" here). Consequent invocations of alpha
remain fine.
If we had started with beta, and then moved to alpha, it would have been the other way around (beta
is fine, alpha
is broken).
I tried running it unders JPDA but while my IDE appears to be connecting it is not actually hitting any breakpoints (probably unrelated issue).
I'm using Grails 2.3.0, JDK 1.6, and Tomcat7.
There is nothing bad that I can see in the logs.
Any ideas what the issue may be, or even just how to approach debugging it?
http://goo.gl/aFKYYb <-- grails app
http://goo.gl/aDP6Lx <-- .war file
Possible Grails defect (although they cannot reproduce):
http://jira.grails.org/browse/GRAILS-10614
I did a "install-templates" and am modifying the scaffolding templates as a work-around.
Edit - yes, confirmed; I forgot to update this response but upgrade to 2.3.1 solves the issue, as per the defect linked.
这篇关于Grails“回应”从.war文件启动时呈现错误的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!