Maxime ARNSTAMM
Maxime ARNSTAMM

Reputation: 5314

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 only the global ones ?

Upvotes: 9

Views: 10057

Answers (3)

jivanic
jivanic

Reputation: 11

omitting path does not work, you must insert empty path:

<form:errors path=""/> 

Upvotes: 0

axtavt
axtavt

Reputation: 242786

As far as I remember, you need to use <form:errors /> without path attribute to do it.

Upvotes: 11

Teja Kantamneni
Teja Kantamneni

Reputation: 17492

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>

Upvotes: 5

Related Questions