@Required is a custom JSR-303 annotation, created within the Play framework. JSR-303 is a specification for validation of Javabeans, which allows for ensuring that a given Java bean's values fall within a set of constraints. Examples of some standard validation annotations:
- @Max - The annotated element must be a number whose value must be lower or equal to the specified maximum.
- @Min - The annotated element must be a number whose value must be higher or equal to the specified minimum.
- @NotNull - The annotated element must not be null.
Each JSR-303 annotation is allowed to define groups, where each group is really just a class. These groups can be used to execute a subset of validations for a given bean. In your particular example, the implementors have defined two interfaces to represent these groups - All and Step1. Then they add the groups to the validation annotations, in order to indicate that those validations belong to the group. So for the below class:
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();
The following will execute the @Required and @MinLength validation for the username field:
validator.validate(bean, All.class);
Whereas the following will execute just the @Required validation (for the username field):
validator.validate(bean, Step1.class);