Play framework @Required

I am new to Java and play. going through sample applications. can you help me understand what is going on in this file. https://github.com/playframework/Play20/blob/master/samples/java/forms/app/models/User.java

I don’t understand why we declare this interface to be “the public interface All {}” and how it is used in this check. "@Required (groups = {All.class, Step1.class})"

+5
source share
1 answer

@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);
+11

All Articles