How to print Global errors only with form:errors?
In my form, i have some specific targeted errors (with path="myField"
) and i'd like to throw global errors, because they span multiple fields.
But if i use <form:errors path="*">
, it will print global AND re-print local errors !
How can i print onl开发者_开发知识库y the global ones ?
As far as I remember, you need to use <form:errors />
without path
attribute to do it.
I am not sure about using form
tag to do that. But Errors
object has methods to getglobalerrors.
EDIT
<spring:hasBindErrors name="input">
<c:forEach items="${errors.globalErrors}" var="errorMessage">
<div id="errors" class="errors">
<c:out value="${errorMessage.defaultMessage}" />
</div>
</c:forEach>
</spring:hasBindErrors>
omitting path does not work, you must insert empty path:
<form:errors path=""/>
精彩评论