Question

I'm validating the input field that's bound to path. I'm using hibernate-validator 4 for this. Now I'd like to highlight the age label so it pops out of the page (bold, red colour etc.). However I'm wondering what the cleanest way to do this is.

<spring:hasBindErrors name="*"/> seems to be for the whole form object instead of for a specific field. Any input is appreciated.

Was it helpful?

Solution

Spring provides special jsp tags for forms, which support this task (highlighing in case of error):

For example this jsp

...
<%@ taglib prefix='form' uri='http://www.springframework.org/tags/form'%>
...
<form:form method="post"
           commandName="myCommand">
  <form:input path="name"
              cssClass="normalLayout"
              cssErrorClass="normalLayout error"/>
  <form:errors path="name"
               cssClass="errorMessage"/>
</form:form>
...

In this case: the input field uses the css class "normalLayout" if every thing is ok, and the css classes "normalLayout" and "name" if there is a validation error for the field.

form:errors is to print the error message generated while validation.

@see http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/view.html#view-jsp-formtaglib

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top