Interface ValidatingField<E extends HasValue.ValueChangeEvent<V>,V>
- Type Parameters:
E
- value change event typeV
- internal binder bean type
- All Superinterfaces:
HasValue<E,
,V> Serializable
- All Known Implementing Classes:
BinderCustomField
,FieldBuilderCustomField
,NullableField
The main purpose of doing things this way is modularity: it allows a field to define its own validation logic, rather than relying on some external component to do so. Of course, this only works for validation checks that can be done by the field itself and are therefore independent of the containing context (e.g., other fields).
This interface would typically be implemented by complex fields composed from sub-fields for which some overall validation
is required. For example, imagine a date range field composed of two LocalDate
fields representing the start
and end date: an overall validation would require that the start date be prior to the end date.
However, for any ValidatingField
validation to take effect, some mechanism must register the validation with
an appropriate Binder
. This happens automatically for fields created by a FieldBuilder
, but can also
be done manually via addValidationTo()
.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
HasValue.ValueChangeEvent<V extends Object>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
-
Method Summary
Modifier and TypeMethodDescriptiondefault <BEAN,
TARGET extends V>
Binder.BindingBuilder<BEAN,TARGET> addValidationTo
(Binder.BindingBuilder<BEAN, TARGET> builder) Add this instance as aValidator
to the given binding.validate
(V value, ValueContext context) Validate this instance.Methods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible, setValue
-
Method Details
-
validate
Validate this instance.- Parameters:
value
- field value to validatecontext
- the value context for validation- Returns:
- the validation result
-
addValidationTo
default <BEAN,TARGET extends V> Binder.BindingBuilder<BEAN,TARGET> addValidationTo(Binder.BindingBuilder<BEAN, TARGET> builder) Add this instance as aValidator
to the given binding.- Type Parameters:
BEAN
- binder bean typeTARGET
- binding target type- Parameters:
builder
- binding builder- Returns:
- updated binding builder
- Throws:
IllegalArgumentException
- ifbuilder
is null
-