You can certainly do various things of this sort... In any case, it would take more than a single line. Therefore, if you need to render something other than just the error messages rendered by the <form:errors> tag, add some custom markup, info, etc, I would recommend extracting your conditional error-rendering logic into a JSP tag file (if you are using JSPs.) (I always recommend using tag files for JSP development. It is a very useful and powerful feature in JSP 2.x that allows to elegantly reuse layout markup and JSP code.) For example, you could create a tag file like this:
Code:
<%@tag description=
"Displays the tag body if validation/binding errors are associated with
the property identified by the given path on the model attribute." %>
<%@attribute name="path" required="true"
description="Path to the property on the model bean for which to check for errors." %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:if test="${not empty path}">
<spring:bind path="${path}">
<c:if test="${not empty status.errorMessages}">
<%-- the content (tag body) provided by caller will be rendered here --%>
<jsp:doBody/>
</c:if>
</spring:bind>
</c:if>
Note that per the JSP spec, tag files must reside under /WEB-INF/tags folder, which is the root for all other (optional) tag sub-folders. So, you could place this file in /WEB-INF/tags/core, and then use it in your pages like this:
Code:
...
<%-- your custom core tag file library definition--%>
<%@ taglib prefix="my-core" tagdir="/WEB-INF/tags/core" %>
...
<form:form ...>
<my-core:if-field-errors path="yourFieldPath">
...whatever you want to display if field errors are detected
(if you need to output something other than std form:errors output!)
</my-core:if-field-errors>
...
</form:form>
This is just one example. You see that the body may be provided for the if-field-errors tag in this example so that each usage of the tag can potentially render different markup in each case. If all you need, for instance, is to display a red asterisk next to the invalid field, you could just create a similar no-body tag. Note the status variable exposed by the <spring:bind> tag. From that variable you can get various useful information including the number of errors, e.g. ${status.errors.errorCount}, etc.
I can't recall or check right now whether the <spring:bind> tag accepts a wild-card for the path attribute similar to <form:errors> to be applied to all errors vs. a single field. Don't see why it shouldn't. Will leave it up to you to investigate. Good luck!