Displaying spring form error outside the form

How can we display form errors outside the form. I know that it can be displayed inside the form with <sf:errors path="nb"></sf:errors>. If I want to display it in a separate one div, how can I do it? I am new to spring, so please help me out.

+5
source share
1 answer

If you plan to display all error messages at the same time, use the following taglib.

<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>

Sort of,

<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>

Note that the name="someBean"tag name attribute <spring:hasBindErrors/>is your actual command object attached to your form.

+6
source

All Articles