Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring form errors custom html

I need to do something like that:

 <form:errors path="*">
        <div class="error">
                <div class="internal">
                    <a href="#" class="close"></a>
                    ${error}
                </div>
                <div class="bar">&nbsp;</div>
                <div class="internal">
                    <input type="button" value="Ok" />
                </div>
        </div>
    </form:errors>

How can I get all the error messages by using the above HTML code? :S

By using <form:errors path="*" cssClass="error" /> it will be inside only one tag

like image 388
ianaz Avatar asked Jul 05 '11 21:07

ianaz


1 Answers

You can use the spring:bind tag to bind a status-variable to your current error messages. Then you can iterate over status.errorMessages like in the example below.

<spring:bind path="*">
  <c:forEach items="${status.errorMessages}" var="error">
    <div class="error">
      <div class="internal">
        <a href="#" class="close"></a>
        ${error}
      </div>
      <div class="bar">&nbsp;</div>
      <div class="internal">
        <input type="button" value="Ok" />
      </div>
    </div>
  </c:forEach>      
</spring:bind>

Don't forget to add the taglib declaration for spring: tags on top of your page:

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
like image 178
Florian Fankhauser Avatar answered Oct 29 '22 08:10

Florian Fankhauser