Wednesday, December 20, 2006
Spring: Error message not displayed in JSP after calling errors.rejectValue
I spent about half an hour trying to debug a simple (seemingly stupid) error today.
I had a controller doing some validation and rejecting a value that it didn't like, as follows:
errors.rejectValue("file", "Attachments.file", args, "File");
In the JSP I had the following boilerplate code to display these errors:
<spring:bind path="Attachments.*">
<b>Got some errors? ${status.errorMessages}</b>
<c:if test="${not empty status.errorMessages}">
<div class="error"><c:forEach var="error"
items="${status.errorMessages}">
<img src="<c:url value="/images/iconWarning.gif"/>"
alt="<fmt:message key="icon.warning"/>" class="icon" />
<c:out value="${error}" escapeXml="false" />
<br />
</c:forEach></div>
</c:if>
</spring:bind>
And
I had a controller doing some validation and rejecting a value that it didn't like, as follows:
errors.rejectValue("file", "Attachments.file", args, "File");
In the JSP I had the following boilerplate code to display these errors:
<spring:bind path="Attachments.*">
<b>Got some errors? ${status.errorMessages}</b>
<c:if test="${not empty status.errorMessages}">
<div class="error"><c:forEach var="error"
items="${status.errorMessages}">
<img src="<c:url value="/images/iconWarning.gif"/>"
alt="<fmt:message key="icon.warning"/>" class="icon" />
<c:out value="${error}" escapeXml="false" />
<br />
</c:forEach></div>
</c:if>
</spring:bind>
And