【发布时间】:2011-06-30 07:16:25
【问题描述】:
我有一个使用 Spring MVC 和 Velocity 的应用程序。在我的一个表单上,我想在页面顶部显示与表单相关的所有错误。我已经想出了如何显示与一个特定字段相关的错误(使用#springShowErrors 宏),但我真的希望在表单顶部有一大块错误,而不是在每个单独项目旁边列出错误.
我已经做了很多谷歌搜索,有些人提出了类似的建议
#if ($status && $status.errors.hasErrors())
#foreach( $error in $status.errorMessages )
<p>$error</p>
#end
#end
...但是当将我的命令对象附加到表单的初始#springBind 宏下方时,这不会给我任何输出。将#springShowErrors 放在每个字段的#springFormInput 宏之后可以正常工作,所以我知道我的验证器正在运行并产生错误。
有什么想法吗?我错过了什么非常愚蠢的事情吗?
这是完整的表格,我在第一次 #springBind 之后尝试不工作
<form name="standardForm" id="standardForm" method="post" action="#springUrl("/requestAccess")">
#springBind("accessRequest")
#if ($status && $status.errors.hasErrors())
#foreach( $error in $status.errorMessages )
<p>$error</p>
#end
#end
<fieldset>
<label for="name">Name</label>
#springFormInput("accessRequest.name" " ")
<label for="company">Company</label>
#springFormInput("accessRequest.company" " ")
<label for="title">Title</label>
#springFormInput("accessRequest.title" " ")
<label for="email">Email</label>
#springFormInput("accessRequest.email" " ")
<button type="submit" value="send">Send</button>
</fieldset>
</form>
感谢您的帮助或建议!
【问题讨论】:
标签: spring validation forms spring-mvc velocity