Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying spring form error outside of form

How can we display form errors out side of form. I know it can be displayed inside of form using <sf:errors path="nb"></sf:errors>. If I want to display it in separate div how can I do it? I am new to spring so please guide me.

like image 538
ntstha Avatar asked Feb 14 '13 09:02

ntstha


1 Answers

You could, if you're planning to display all error messages simultaneously, using the following taglib.

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

Something like,

<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 attribute name="someBean" of the tag <spring:hasBindErrors/> is your actual command object which is bound to your form.

like image 64
Lion Avatar answered Oct 17 '22 08:10

Lion