Reputation: 529
I am using hibernate annotations to validate the field with spring form validation.
This is my model class :
public class NewPasword {
@NotEmpty(message="Please Provide Password")
@Pattern(regexp = "^(?=.*?[A-Z])(?=.*?[0-9])(?=\\S+$).{8,}$", message = "{encryptedpassword.required}")
@Size(min=8, max=19)
private String newPassword;
........
.......
}
This is my JSP;
.....
<div class="row">
<form:input path="field" />
<form:error path="field" />
</div>
.....
While executing all validation message is displaying on the front end which should not be.
can any one suggest me how can i get only one validation message prior from up.
like : if field is empty then message should be only "please enter the field"
if field not matched to pattern then message should be only "please enter a valid field"
if field is < 8 and > 19 then message should be only "length should be between 8-19"
if any more information required please ask.
Upvotes: 1
Views: 55
Reputation: 627
You can solve this with Group
s and a GroupSequence
@GroupSequence({ Step1.class, Step2.class, Step3.class })
public class NewPasword {
public interface Step1 {}
public interface Step2 {}
public interface Step3 {}
@NotEmpty(message="Please Provide Password",groups = Step1.class)
@Pattern(regexp = "^(?=.*?[A-Z])(?=.*?[0-9])(?=\\S+$).{8,}$", message = "{encryptedpassword.required}", groups = Step2.class)
@Size(min=8, max=19, groups = Step3.class)
private String newPassword;
}
See reference: Grouping
Upvotes: 2