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>>
com.vaadin.flow.data.binder.ValidationResultcheckGreaterThanMax(V value, V maxValue) Deprecated.static <V> com.vaadin.flow.data.binder.ValidationResultcheckRequired(boolean required, V value, V emptyValue) Deprecated.since 24.5, usevalidateRequiredConstraint(String, boolean, Object, Object)instead.static <V extends Comparable<V>>
com.vaadin.flow.data.binder.ValidationResultcheckSmallerThanMin(V value, V minValue) Deprecated.since 24.5, usevalidateMinConstraint(String, Comparable, Comparable)instead.static <V extends Comparable<V>>
com.vaadin.flow.data.binder.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 com.vaadin.flow.data.binder.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>>
com.vaadin.flow.data.binder.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 com.vaadin.flow.data.binder.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 com.vaadin.flow.data.binder.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> com.vaadin.flow.data.binder.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> com.vaadin.flow.data.binder.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> com.vaadin.flow.data.binder.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>> com.vaadin.flow.data.binder.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>> com.vaadin.flow.data.binder.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>> com.vaadin.flow.data.binder.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>> com.vaadin.flow.data.binder.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 com.vaadin.flow.data.binder.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 com.vaadin.flow.data.binder.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 com.vaadin.flow.data.binder.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.