There are two problems:
1.Sping / MVC use hibernate validater, custom validator, how to show message? for example: Cross-field validation using Hibernate Validator (JSR 303)
@FieldMatch.List({ @FieldMatch(fieldName="password",verifyName="passwordVerify",message="password confirm valid!", groups={Default.class}) }) @ScriptAssert(lang="javascript",script="_this.name.equals(_this.verifyCode)") public class LoginForm {...}
How to show message in jsp with resource properties file?
NotEmpty.loginForm.name = "username cannot be empty!" NotEmpty.loginForm.password = "Password cannot be empty!"
2. I want to use a group validator with spring mvc, for example, one user form for login and registration
@FieldMatch.List({ @FieldMatch(fieldName="password",verifyName="passwordVerify",message="password confirm valid!", groups={Default.class}) })@ScriptAssert(lang="javascript",script="_this.name.equals(_this.verifyCode)",groups={Default.class,LoginChecks.class,RegisterChecks.class}) public class LoginForm { @NotEmpty(groups={Default.class,LoginChecks.class,RegisterChecks.class}) @Size(min=3,max=10,groups={LoginChecks.class,RegisterChecks.class}) private String name; @NotEmpty(groups={Default.class,LoginChecks.class,RegisterChecks.class}) @Size(max=16,min=5,groups={LoginChecks.class,RegisterChecks.class}) private String password; private String passwordVerify; @Email(groups={Default.class,LoginChecks.class,RegisterChecks.class}) private String email; private String emailVerify; ... }
Controller parameter annotations: @valid, any support group support annotations by group?
First post :)
spring-mvc hibernate-validator bean-validation
hidehai
source share