I have been trying this for a while but can’t find the right solution.
I want to use JSTL to check if there is any binding errors (field error or global error) that happened in my Spring MVC 2.5.
I know I can use this code:
<p>
<spring:hasBindErrors name="searchItems">
An Error has occured
</spring:hasBindErrors>
</p>
But I want to utilize JSTL to check for any errors.
I have tried this one using JSTL:
<c:if test="${not empty errors}">
An Error has occured
</c:if>
But it seems that I cannot catch it correctly.
I need to used JSTL since there are other parts of the JSP that relies on the presence or absence of a binding errors.
As said
Just use (It just works on Spring MVC 2.5 – Not portable for Spring MVC 3.0 although i suppose it is requestScope[‘bindingResult.<COMMAND_NAME_GOES_HERE>.allErrors’])
Keep in mind default command name is The non-qualified command class name with The first letter lowercased. Notice bellow command name is pet
So your form should looks like
Unless you use @ModelAttribute
This way, your form should looks like