Class WholeBeanValidator

java.lang.Object
org.dellroad.stuff.vaadin24.util.WholeBeanValidator
All Implemented Interfaces:
Validator<Object>, Serializable, BiFunction<Object,ValueContext,ValidationResult>

public class WholeBeanValidator extends Object implements Validator<Object>
Applies JSR 303 bean validation constraints that are attached to the bean as a whole (not to an individual property).

The BeanValidator class validates individual bean properties but does not handle "whole bean" validation constraints. This class can be used to cover that gap. This validator does not recurse on the properties of the bean (for that, annotate those properties with @Valid and rely on BeanValidator per-property validation).

See ValidatingBean for a simpler, non-JSR 303 alternative to this class.

This is a bean-level validator, so any Binder using this validator will need access to an actual bean in order to validate (e.g., via Binder.setBean(), Binder.writeBean(), Binder.writeBeanIfValid(), etc.), otherwise you'll get an IllegalStateException with bean level validators have been configured but no bean is currently set.

See Also:
  • Field Details

    • beanType

      protected final Class<?> beanType
      Bean type.
  • Constructor Details

    • WholeBeanValidator

      public WholeBeanValidator(Class<?> beanType)
      Constructor.
      Parameters:
      beanType - bean type
      Throws:
      NullPointerException - if beanType is null
  • Method Details

    • setValidationGroups

      public void setValidationGroups(Class<?>[] groups)
      Configure an alternate set of validation group(s) which will get passed to Validator.validate().

      The default is an empty array, i.e., Default.

      Parameters:
      groups - group(s) to validate, or null for Default
    • setValidatorFactory

      public void setValidatorFactory(jakarta.validation.ValidatorFactory validatorFactory)
      Configure a custom ValidatorFactory.

      If this property is left unset, then the factory returned by BeanValidator.getJavaxBeanValidatorFactory() is used.

      Parameters:
      validatorFactory - custom validation factory, or null for none
    • apply

      public ValidationResult apply(Object bean, ValueContext valueContext)
      Specified by:
      apply in interface BiFunction<Object,ValueContext,ValidationResult>
      Specified by:
      apply in interface Validator<Object>