@Requiredis a JSR-303 user annotation created as part of the Play program. JSR-303 is a Javabeans validation specification that ensures that Java beans are a set of constraints. Examples of some standard validation annotations:
- @Max - the annotated element must be a number whose value must be lower than or equal to the specified maximum value.
- @Min - the annotated element must be a number whose value must be higher or equal to the specified minimum.
- @NotNull - An annotated element must not be null.
JSR-303 , . bean. - All Step1. , , . , :
public class MyBean {
@Required(groups = {All.class, Step1.class})
@MinLength(value = 4, groups = {All.class})
public String username;
}
MyBean bean = new MyBean();
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
@Required @MinLength username:
validator.validate(bean, All.class);
@Required ( username):
validator.validate(bean, Step1.class);