Package com.vaadin.flow.component.shared
Class ValidationUtil
java.lang.Object
com.vaadin.flow.component.shared.ValidationUtil
Util methods for component validation
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V extends Comparable<V>>
ValidationResultcheckGreaterThanMax(V value, V maxValue) Deprecated.static <V> ValidationResultcheckRequired(boolean required, V value, V emptyValue) Deprecated.since 24.5, usevalidateRequiredConstraint(String, boolean, Object, Object)instead.static <V extends Comparable<V>>
ValidationResultcheckSmallerThanMin(V value, V minValue) Deprecated.since 24.5, usevalidateMinConstraint(String, Comparable, Comparable)instead.static <V extends Comparable<V>>
ValidationResultvalidateMaxConstraint(String errorMessage, V value, V maxValue) Checks if the value satisfies the maximum value constraint and returns aValidationResult.ok()orValidationResult.error()with the given error message depending on the result.static ValidationResultvalidateMaxLengthConstraint(String errorMessage, String value, Integer maxLength) Checks if the value satisfies the maximum length constraint and returns aValidationResult.ok()orValidationResult.error()with the given error message depending on the result.static <V extends Comparable<V>>
ValidationResultvalidateMinConstraint(String errorMessage, V value, V minValue) Checks if the value satisfies the minimum value constraint and returns aValidationResult.ok()orValidationResult.error()with the given error message depending on the result.static ValidationResultvalidateMinLengthConstraint(String errorMessage, String value, Integer minLength) Checks if the value satisfies the minimum length constraint and returns aValidationResult.ok()orValidationResult.error()with the given error message depending on the result.static ValidationResultvalidatePatternConstraint(String errorMessage, String value, String pattern) Checks if the value satisfies the pattern constraint and returns aValidationResult.ok()orValidationResult.error()with the given error message depending on the result.static <V> ValidationResultvalidateRequiredConstraint(String errorMessage, boolean required, V value, V emptyValue) Checks if the value satistifies the required constraint and returns aValidationResult.ok()orValidationResult.error()with the given error message depending on the result.
-
Method Details
-
checkRequired
@Deprecated public static <V> ValidationResult checkRequired(boolean required, V value, V emptyValue) Deprecated.since 24.5, usevalidateRequiredConstraint(String, boolean, Object, Object)instead.Checks if the value satistifies the required constraint and returns aValidationResult.ok()orValidationResult.error()with an empty error message depending on the result.- Type Parameters:
V- the type of the value- Parameters:
required- whether the constraint is enabledvalue- the value to validateemptyValue- 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 aValidationResult.ok()orValidationResult.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 failsrequired- whether the constraint is enabledvalue- the value to validateemptyValue- 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.since 24.5, usevalidateMaxConstraint(String, Comparable, Comparable)instead.Checks if the value satisfies the maximum value constraint and returns aValidationResult.ok()orValidationResult.error()with an empty error message depending on the result.- Type Parameters:
V- the type of the value- Parameters:
value- the value to validatemaxValue- 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 aValidationResult.ok()orValidationResult.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 failsvalue- the value to validatemaxValue- 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.since 24.5, usevalidateMinConstraint(String, Comparable, Comparable)instead.Checks if the value satisfies the minimum value constraint and returns aValidationResult.ok()orValidationResult.error()with an empty error message depending on the result.- Type Parameters:
V- the type of the value- Parameters:
value- the value to validateminValue- 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 aValidationResult.ok()orValidationResult.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 failsvalue- the value to validateminValue- 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 aValidationResult.ok()orValidationResult.error()with the given error message depending on the result.- Parameters:
errorMessage- the error message to return if the check failsvalue- the value to validateminLength- 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 aValidationResult.ok()orValidationResult.error()with the given error message depending on the result.- Parameters:
errorMessage- the error message to return if the check failsvalue- the value to validatemaxLength- 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 aValidationResult.ok()orValidationResult.error()with the given error message depending on the result.- Parameters:
errorMessage- the error message to return if the check failsvalue- the value to validatepattern- the pattern to match- Returns:
ValidationResult.ok()if the value matches the pattern,ValidationResult.error()otherwise
-
validateMaxConstraint(String, Comparable, Comparable)instead.