I would like to know if it is possible to stop execution of other validators while one failed?
I have some bean, annotated like this
import org.hibernate.validator.constraints.*;
/*...*/
@NotBlank(message = SignupForm.NOT_BLANK_MESSAGE)
@Email(message = SignupForm.EMAIL_MESSAGE)
private String email;
@NotBlank(message = SignupForm.NOT_BLANK_MESSAGE)
@Length(min = 6, message = SignupForm.PASSWORD_LENGTH_TOO_SHORT_MESSAGE)
private String password;
and heres my JSP
<form:label path="email"><s:message code="email" /></form:label>
<form:errors path="email" element="div" class="text-error"/>
<form:input path="email" class="input-block-level" placeholder="Email address" />
<form:label path="email2"><s:message code="repeat_email" /></form:label>
<form:errors path="email2" element="div" class="text-error"/>
<form:input path="email2" class="input-block-level" placeholder="Email address" />
<form:label path="password"><s:message code="password" /></form:label>
<form:errors path="password" element="div" class="text-error"/>
<form:password path="password" class="input-block-level" placeholder="Password" />
<form:label path="password2"><s:message code="repeat_password" /> </form:label>
<form:errors path="password2" element="div" class="text-error"/>
<form:password path="password2" class="input-block-level" placeholder="Password" />
Now - on my page, when I try to submit empty form I get
E-mail
The value may not be empty!
and
Password
Password must be at least 6 characters long
The value may not be empty!
For password
field I get errors from both validators - which is quite undesirable.
In case of email
field I understand that empty string is a valid email address (?!) and thats why I only get one message at the time.
So is it possible to run validations in specified order and stop processing after first fail or get only first message?