Hi All,
I'm trying to use the
Constraint composition and would like to define the group for each composited constraint as the following example: -
The Composite ConstraintCode:
@Target({
ElementType.FIELD,
ElementType.METHOD,
ElementType.PARAMETER,
ElementType.TYPE,
ElementType.ANNOTATION_TYPE
})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@DummyValid1(group = Group1.class)
@DummyValid2(group = Group2.class)
@Constraint(validatedBy = {})
public @interface DummyCompositeValid {
String message() default "The bean is invalid.";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
The data beanCode:
@DummyCompositeValid
public class DummyBean {
//Fields declaration, Setter and Getter
}
The business validation methodCode:
this.validator.validate(dummyBean, Group1.class, Group2.class);
The result is the dummyBean has not been validated. I'm confused that since the group is worked well when it is defined directly without the composite constraint as the following: -
The data beanCode:
@DummyValid1(group = Group1.class)
@DummyValid2(group = Group2.class)
public class DummyBean {
//Fields declaration, Setter and Getter
}
Could you please help to advise and explain further? Thank you very much for your help in advance. I'm looking forward to hearing from you soon.
Regards,
Charlee Ch.