Grails 命令对象可为空约束
我最近将 1.3.6 应用程序升级到 Grails2。我的测试用例开始失败
这是场景,我有一个命令对象和一个约束。当请求命中操作时,不带参数 name
(localhost:8080/app-name/Book/test?i=0
) 我收到验证错误。 Grails 文档说命令对象字段默认可为空。从这次测试来看,似乎不是。我的问题是如何使所有命令对象全局都可以为 null?代码如下,
class BookController {
def test = {TestCommand cmd ->
cmd.validate()
if (cmd.hasErrors()) {
println "has Errors"
render 'Error'
} else {
println "Success"
render 'Hello World'
}
}
}
命令对象是:
class TestCommand {
int i;
String name
static constraints = {
name(password: true)
}
}
I recently upgraded a 1.3.6 application to Grails2. My test cases have started failing
Here is the scenario, I have a command object and a constraint. When the request hits the action, without the parameter name
(localhost:8080/app-name/Book/test?i=0
)
I am getting a validation error. Grails doc says Command Object fields are nullable by default. Looks like it is not, from this test. My question is how do I make them nullable true globally for all command objects? Code below,
class BookController {
def test = {TestCommand cmd ->
cmd.validate()
if (cmd.hasErrors()) {
println "has Errors"
render 'Error'
} else {
println "Success"
render 'Hello World'
}
}
}
Command Object is :
class TestCommand {
int i;
String name
static constraints = {
name(password: true)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明这是一个 Grails 错误。 Grails 2.0 更改了命令对象的默认可为空值的行为。这是 JIRA
It turned out to be a Grails bug. Grails 2.0 has changed behaviour about default nullable value for Command Objects. Here is the JIRA