Interface FormValidator

All Known Implementing Classes:
CompareValidator, DateRangeValidator
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface FormValidator
Functional interface for form-level validation.

FormValidator allows validation logic that spans multiple fields, such as verifying that a password confirmation matches the original password, or ensuring that a date range is valid (start date before end date).

FormValidators receive a ValidationContext containing all form field values, enabling cross-field validation scenarios.

Usage:


 // Lambda-style form validator
 FormValidator passwordMatch = context -> {
     String password = (String) context.getFieldValue("password");
     String confirm = (String) context.getFieldValue("confirmPassword");
     if (password != null && !password.equals(confirm)) {
         return ValidationResult.invalid("Passwords do not match");
     }
     return ValidationResult.valid();
 };

 // Add to ValidatedForm
 validatedForm.addFormValidator(passwordMatch);

 // Or use the built-in CompareValidator
 validatedForm.addFormValidator(
     new CompareValidator("password", "confirmPassword", CompareValidator.Operation.EQUALS)
         .withMessage("Password confirmation must match")
 );
 
Since:
2025
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Validates the form using all field values from the context.
  • Method Details

    • validate

      Validates the form using all field values from the context.
      Parameters:
      context - The validation context containing all form field values
      Returns:
      The validation result