Grails“响应"从 .war 文件启动时呈现错误的视图 [英] Grails "respond" renders the wrong view when launched from .war file

查看:13
本文介绍了Grails“响应"从 .war 文件启动时呈现错误的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Grails 应用程序有许多使用新的 RESTful响应"功能自动生成的(来自标准 Grails 2.3.0 脚手架)代码.例如,索引方法一般是这样的:

def index(Integer max) {params.max = Math.min(max ?: 10, 100)响应 Alpha.list(params), 模型:[alphaInstanceCount: Alpha.count()]}

当应用程序作为grails run-app"运行时,这完全正常,但是当应用程序打包为 .war 并在非嵌入式 servlet 容器中以这种方式启动时会失败.

它适用于使用的第一个控制器/视图组合,但对于后续组合使用渲染的第一个视图的视图文件夹.例如,如果我们先尝试 /alpha/index,然后再尝试 /beta/index 那么 /alpha/index 将工作正常,但是/beta/index 将使用 /alpha/index.gsp 进行渲染(而不是预期的 /beta/index.gsp).

但是,如果我将方法更改为:

def index(Integer max) {params.max = Math.min(max ?: 10, 100)渲染(视图:'索引',模型:[alphaInstanceList:Alpha.list(参数),alphaInstanceCount:Alpha.count()])}

然后它在两个部署选项中都能正常工作.

我在一些 .gsp-s 中添加了一些调试代码以输出 ${this.getGroovyPageFileName()}${controllerName}${actionName}.

这表明虽然控制器和操作名称始终是预期的名称,但在第一个视图之后呈现的视图上使用的视图仍然是第一个视图上使用的视图.

例如,/alpha/index 的初始调用的控制器为 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 似乎正在连接,但实际上并没有遇到任何断点(可能无关的问题).

我使用的是 Grails 2.3.0、JDK 1.6 和 Tomcat7.

我在日志中没有看到任何不好的东西.

任何想法可能是什么问题,甚至只是如何进行调试?

http://goo.gl/aFKYYb <-- grails 应用程序

http://goo.gl/aDP6Lx <-- .war 文件

解决方案

可能的 Grails 缺陷(尽管它们无法重现):

http://jira.grails.org/browse/GRAILS-10614

我做了一个安装模板",正在修改脚手架模板作为解决方法.

编辑 - 是的,已确认;我忘记更新此响应,但根据链接的缺陷升级到 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆