Class ValidationUtil

java.lang.Object
com.vaadin.flow.component.shared.ValidationUtil

public class ValidationUtil extends Object
Util methods for component validation
  • Method Details

    • checkRequired

      @Deprecated public static <V> ValidationResult checkRequired(boolean required, V value, V emptyValue)
      Checks if the value satistifies the required constraint and returns a ValidationResult.ok() or ValidationResult.error() with an empty error message depending on the result.
      Type Parameters:
      V - the type of the value
      Parameters:
      required - whether the constraint is enabled
      value - the value to validate
      emptyValue - the value considered to be empty
      Returns:
      ValidationResult.ok() if the value does not equal to the empty value, ValidationResult.error() otherwise
    • validateRequiredConstraint

      public static <V> ValidationResult validateRequiredConstraint(String errorMessage, boolean required, V value, V emptyValue)
      Checks if the value satistifies the required constraint and returns a ValidationResult.ok() or ValidationResult.error() with the given error message depending on the result.
      Type Parameters:
      V - the type of the value
      Parameters:
      errorMessage - the error message to return if the check fails
      required - whether the constraint is enabled
      value - the value to validate
      emptyValue - the value considered to be empty
      Returns:
      ValidationResult.ok() if the value does not equal to the empty value, ValidationResult.error() otherwise
    • checkGreaterThanMax

      @Deprecated public static <V extends Comparable<V>> ValidationResult checkGreaterThanMax(V value, V maxValue)
      Deprecated.
      Checks if the value satisfies the maximum value constraint and returns a ValidationResult.ok() or ValidationResult.error() with an empty error message depending on the result.
      Type Parameters:
      V - the type of the value
      Parameters:
      value - the value to validate
      maxValue - the maximum allowed value
      Returns:
      ValidationResult.ok() if the value is smaller or equal to the maximum value, ValidationResult.error() otherwise
    • validateMaxConstraint

      public static <V extends Comparable<V>> ValidationResult validateMaxConstraint(String errorMessage, V value, V maxValue)
      Checks if the value satisfies the maximum value constraint and returns a ValidationResult.ok() or ValidationResult.error() with the given error message depending on the result.
      Type Parameters:
      V - the type of the value
      Parameters:
      errorMessage - the error message to return if the check fails
      value - the value to validate
      maxValue - the maximum allowed value
      Returns:
      ValidationResult.ok() if the value is smaller or equal to the maximum value, ValidationResult.error() otherwise
    • checkSmallerThanMin

      @Deprecated public static <V extends Comparable<V>> ValidationResult checkSmallerThanMin(V value, V minValue)
      Deprecated.
      Checks if the value satisfies the minimum value constraint and returns a ValidationResult.ok() or ValidationResult.error() with an empty error message depending on the result.
      Type Parameters:
      V - the type of the value
      Parameters:
      value - the value to validate
      minValue - the minimum allowed value
      Returns:
      ValidationResult.ok() if the value is greater or equal to the minimum value, ValidationResult.error() otherwise
    • validateMinConstraint

      public static <V extends Comparable<V>> ValidationResult validateMinConstraint(String errorMessage, V value, V minValue)
      Checks if the value satisfies the minimum value constraint and returns a ValidationResult.ok() or ValidationResult.error() with the given error message depending on the result.
      Type Parameters:
      V - the type of the value
      Parameters:
      errorMessage - the error message to return if the check fails
      value - the value to validate
      minValue - the minimum allowed value
      Returns:
      ValidationResult.ok() if the value is greater or equal to the minimum value, ValidationResult.error() otherwise
    • validateMinLengthConstraint

      public static ValidationResult validateMinLengthConstraint(String errorMessage, String value, Integer minLength)
      Checks if the value satisfies the minimum length constraint and returns a ValidationResult.ok() or ValidationResult.error() with the given error message depending on the result.
      Parameters:
      errorMessage - the error message to return if the check fails
      value - the value to validate
      minLength - the minimum allowed length
      Returns:
      ValidationResult.ok() if the value is longer than or equal to the minimum length, ValidationResult.error() otherwise
    • validateMaxLengthConstraint

      public static ValidationResult validateMaxLengthConstraint(String errorMessage, String value, Integer maxLength)
      Checks if the value satisfies the maximum length constraint and returns a ValidationResult.ok() or ValidationResult.error() with the given error message depending on the result.
      Parameters:
      errorMessage - the error message to return if the check fails
      value - the value to validate
      maxLength - the maximum allowed length
      Returns:
      ValidationResult.ok() if the value is shorter than or equal to the maximum length, ValidationResult.error() otherwise
    • validatePatternConstraint

      public static ValidationResult validatePatternConstraint(String errorMessage, String value, String pattern)
      Checks if the value satisfies the pattern constraint and returns a ValidationResult.ok() or ValidationResult.error() with the given error message depending on the result.
      Parameters:
      errorMessage - the error message to return if the check fails
      value - the value to validate
      pattern - the pattern to match
      Returns:
      ValidationResult.ok() if the value matches the pattern, ValidationResult.error() otherwise