在表格外显示弹簧表格错误
问题内容:
我们如何在表格之外显示表格错误。我知道它可以使用形式显示在表单中<sf:errors path="nb"></sf:errors>
。如果要单独显示它,div
该怎么办?我是spring新手,请引导我。
问题答案:
如果您打算同时显示所有错误消息,则可以使用以下标记库。
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
就像是,
<spring:hasBindErrors htmlEscape="true" name="someBean">
<c:if test="${errors.errorCount gt 0}">
<h4>The error list :</h4>
<font color="red">
<c:forEach items="${errors.allErrors}" var="error">
<spring:message code="${error.code}"
arguments="${error.arguments}"
text="${error.defaultMessage}"/><br/>
</c:forEach>
</font>
</c:if>
</spring:hasBindErrors>
请注意,name="someBean"
标记的name属性<spring:hasBindErrors/>
是绑定到表单的实际命令对象。