我有一个创建和保存方法如下:
def create () {
def myColorInstance = new Color()
return (colorInstance: myColorInstance]
}
def save () {
Date someDate = params.date("somedate", "MM/dd/yyyy")
int someInt = params.int("someInt")
color = colorService.add(params.colorname, someDate, someInt)
if (color.hasErrors())
render (view: "create", model: [colorInstance: color])
else
redirect (action: "list")
}
在我的布局页面上,我有以下内容:
<g:hasErrors>
<div class="alert alert-error">Please try submitting again</div>
</g:hasErrors>
我得到的行为是,当用户输入某些内容并且验证失败时。当他们第二次提交(再次没有输入任何内容)时,他们看到了消息Please try submitting again
并且 url 更改为http://localhost:8080/myapp/color/save
so,然后我的应用程序失败并显示消息:“无法将具有类 'null' 的对象'null' 转换为类 'int'。尝试' java.lang.Integer' 代替"
处理这种情况的最佳方法是什么?我希望用户在顶部看到错误消息,他们应该能够再次更正错误并尝试再次提交,它应该可以工作..