I performed an ordered validation using GroupSequence, but generally speaking, the implementation of the validation validation of GroupSequence beans is not transparent.
Meaning, until the first group is fully verified, you cannot activate the verification of the second group.
eg.
I have 3 tested fields with custom validators. The idea is quite simple: each field should be checked using a set of validators from top to bottom independently (decreasing power).
@StringPropertyNotNullOrEmptyConstraint(message = "Group name is required", groups = {ValidationStep1.class}) private final StringProperty groupName; @StringPropertyNotNullOrEmptyConstraint(message = "Group password is required", groups = {ValidationStep1.class}) @StringPropertyMatchConstraint(message = "The given password phrases do not match", dependentProperties = {"groupPasswordMatch"}, groups = {ValidationStep2.class}) private final StringProperty groupPassword; @StringPropertyNotNullOrEmptyConstraint(message = "Group password match is required", groups = {ValidationStep1.class}) @StringPropertyMatchConstraint(message = "The given passwords phrases do not match", dependentProperties = {"groupPassword"}, groups = {ValidationStep2.class}) private final StringProperty groupPasswordMatch; public interface ValidationStep1 { } public interface ValidationStep2 { } @GroupSequence({GroupDialogModel.class, ValidationStep1.class, ValidationStep2.class}) public interface GroupDialogModelValidationSequence { } ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); Validator validator = validatorFactory.getValidator(); Set<ConstraintViolation<GroupDialogModel>> constraintViolations = validator.validate(this, GroupDialogModelValidationSequence.class);
A caveat to this approach is that each field must pass through ValidationStep1 first, and only after each verification of step 1 is successful will it go to step 2. For example, even if the password fields are not empty, but contain different values, check they succeed if the group name field does not contain any value. And only after I enter some value in the group name, the group ValidationStep1 will be successful, and then display the result of the ValidationStep2 check (passwords do not match).
Creating each group for each field in each sequence is IMHO bad practice, but it seems like there is no other choice.
Any other solution is of great importance.
source share