BEAN - the bean type, must match the Binder bean typeFIELDVALUE - the value type of the fieldTARGET - the target data type of the binding, matches the field type
until a converter has been setprotected static class Binder.BindingBuilderImpl<BEAN,FIELDVALUE,TARGET> extends Object implements Binder.BindingBuilder<BEAN,TARGET>
BindingBuilder.| Modifier | Constructor and Description |
|---|---|
protected |
BindingBuilderImpl(Binder<BEAN> binder,
HasValue<?,FIELDVALUE> field,
Converter<FIELDVALUE,TARGET> converterValidatorChain,
BindingValidationStatusHandler statusHandler)
Creates a new binding builder associated with the given field.
|
| Modifier and Type | Method and Description |
|---|---|
Binder.BindingBuilder<BEAN,TARGET> |
asRequired(ErrorMessageProvider errorMessageProvider)
Sets the field to be required.
|
Binder.BindingBuilder<BEAN,TARGET> |
asRequired(Validator<TARGET> customRequiredValidator)
Sets the field to be required and delegates the required check to a
custom validator.
|
Binder.Binding<BEAN,TARGET> |
bind(String propertyName)
Completes this binding by connecting the field to the property with
the given name.
|
Binder.Binding<BEAN,TARGET> |
bind(ValueProvider<BEAN,TARGET> getter,
Setter<BEAN,TARGET> setter)
Completes this binding using the given getter and setter functions
representing a backing bean property.
|
protected void |
checkUnbound()
Throws if this binding is already completed and cannot be modified
anymore.
|
protected Binder<BEAN> |
getBinder()
Returns the
Binder connected to this Binding
instance. |
HasValue<?,FIELDVALUE> |
getField()
Gets the field the binding is being built for.
|
<NEWTARGET> |
withConverter(Converter<TARGET,NEWTARGET> converter)
Maps the binding to another data type using the given
Converter. |
protected <NEWTARGET> |
withConverter(Converter<TARGET,NEWTARGET> converter,
boolean resetNullRepresentation)
Implements
withConverter(Converter) method with additional
possibility to disable (reset) default null representation converter. |
Binder.BindingBuilder<BEAN,TARGET> |
withValidationStatusHandler(BindingValidationStatusHandler handler)
Sets a
BindingValidationStatusHandler to track validation
status changes. |
Binder.BindingBuilder<BEAN,TARGET> |
withValidator(Validator<? super TARGET> validator)
Adds a validator to this binding.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitasRequired, asRequired, withConverter, withConverter, withNullRepresentation, withStatusLabel, withValidator, withValidator, withValidator, withValidatorprotected BindingBuilderImpl(Binder<BEAN> binder, HasValue<?,FIELDVALUE> field, Converter<FIELDVALUE,TARGET> converterValidatorChain, BindingValidationStatusHandler statusHandler)
binder - the binder this instance is connected to, not nullfield - the field to bind, not nullconverterValidatorChain - the converter/validator chain to use, not nullstatusHandler - the handler to track validation status, not nullpublic Binder.Binding<BEAN,TARGET> bind(ValueProvider<BEAN,TARGET> getter, Setter<BEAN,TARGET> setter)
Binder.BindingBuilder
When a bean is bound with Binder.setBean(Object), the field
value is set to the return value of the given getter. The property
value is then updated via the given setter whenever the field value
changes. The setter may be null; in that case the property value is
never updated and the binding is said to be read-only.
If the Binder is already bound to some bean, the newly bound field is associated with the corresponding bean property as described above.
If the bound field implements HasValidator, then the binding
instance returned by this method will subscribe for field's
ValidationStatusChangeEvents and will validate itself
upon receiving them.
The getter and setter can be arbitrary functions, for instance implementing user-defined conversion or validation. However, in the most basic use case you can simply pass a pair of method references to this method as follows:
class Person {
public String getName() { ... }
public void setName(String name) { ... }
}
TextField nameField = new TextField();
binder.forField(nameField).bind(Person::getName, Person::setName);
Note: when a null setter is given the field
will be marked as readonly by invoking HasValue.setReadOnly(boolean).
bind in interface Binder.BindingBuilder<BEAN,TARGET>getter - the function to get the value of the property to the
field, not nullsetter - the function to write the field value to the property or
null if read-onlypublic Binder.Binding<BEAN,TARGET> bind(String propertyName)
Binder.BindingBuilderPropertySet.
For a Binder created using the
Binder(Class) constructor, introspection will be used
to find a Java Bean property. If a JSR-303 bean validation
implementation is present on the classpath, a BeanValidator
is also added to the binding.
The property must have an accessible getter method. It need not have
an accessible setter; in that case the property value is never
updated and the binding is said to be read-only.
Nested property, when supported, can be referenced using the bean
path, starting from the root class, for example 'address.streetName'.
All intermediate getters must exist (e.g. getAddress()), and
should never return null, otherwise binding will fail.
Note: when the binding is read-only the field
will be marked as readonly by invoking HasValue.setReadOnly(boolean).
bind in interface Binder.BindingBuilder<BEAN,TARGET>propertyName - the name of the property to bind, not nullBinder.BindingBuilder.bind(ValueProvider, Setter)public Binder.BindingBuilder<BEAN,TARGET> withValidator(Validator<? super TARGET> validator)
Binder.BindingBuilderwithValidator in interface Binder.BindingBuilder<BEAN,TARGET>validator - the validator to add, not nullBinder.BindingBuilder.withValidator(SerializablePredicate, String),
Binder.BindingBuilder.withValidator(SerializablePredicate, ErrorMessageProvider)public <NEWTARGET> Binder.BindingBuilder<BEAN,NEWTARGET> withConverter(Converter<TARGET,NEWTARGET> converter)
Binder.BindingBuilderConverter.
A converter is capable of converting between a presentation type,
which must match the current target data type of the binding, and a
model type, which can be any data type and becomes the new target
type of the binding. When invoking
Binder.BindingBuilder.bind(ValueProvider, Setter), the target type of the binding
must match the getter/setter types.
For instance, a TextField can be bound to an integer-typed
property using an appropriate converter such as a
StringToIntegerConverter.
The converted value is not applied back to the field by default, this
can be controlled with the method
Binder.Binding.setConvertBackToPresentation(boolean).
withConverter in interface Binder.BindingBuilder<BEAN,TARGET>NEWTARGET - the type to convert toconverter - the converter to use, not nullBinder.Binding.setConvertBackToPresentation(boolean)public Binder.BindingBuilder<BEAN,TARGET> withValidationStatusHandler(BindingValidationStatusHandler handler)
Binder.BindingBuilderBindingValidationStatusHandler to track validation
status changes.
The validation state of each field is updated whenever the user modifies the value of that field.
This method allows to customize the way a binder displays error messages.
The method may be called only once. It means there is no chain unlike
Binder.BindingBuilder.withValidator(Validator) or
Binder.BindingBuilder.withConverter(Converter). Also it means that the shorthand
method Binder.BindingBuilder.withStatusLabel(HasText) also may not be called after
this method.
withValidationStatusHandler in interface Binder.BindingBuilder<BEAN,TARGET>handler - status change handlerBinder.BindingBuilder.withStatusLabel(HasText)public Binder.BindingBuilder<BEAN,TARGET> asRequired(ErrorMessageProvider errorMessageProvider)
Binder.BindingBuilderHasValue.getEmptyValue()
returns.asRequired in interface Binder.BindingBuilder<BEAN,TARGET>errorMessageProvider - the provider for localized validation error messageHasValue.setRequiredIndicatorVisible(boolean),
HasValue.isEmpty()public Binder.BindingBuilder<BEAN,TARGET> asRequired(Validator<TARGET> customRequiredValidator)
Binder.BindingBuilderasRequired in interface Binder.BindingBuilder<BEAN,TARGET>customRequiredValidator - validator responsible for the required checkHasValue.setRequiredIndicatorVisible(boolean)protected <NEWTARGET> Binder.BindingBuilder<BEAN,NEWTARGET> withConverter(Converter<TARGET,NEWTARGET> converter, boolean resetNullRepresentation)
withConverter(Converter) method with additional
possibility to disable (reset) default null representation converter.
The method withConverter(Converter) calls this method with
true provided as the second argument value.
NEWTARGET - the type to convert toconverter - the converter to use, not nullresetNullRepresentation - if true then default null representation will be
deactivated (if not yet), otherwise it won't be removedIllegalStateException - if bind has already been calledwithConverter(Converter)protected Binder<BEAN> getBinder()
Binder connected to this Binding
instance.protected void checkUnbound()
IllegalStateException - if this binding is already boundpublic HasValue<?,FIELDVALUE> getField()
Binder.BindingBuildergetField in interface Binder.BindingBuilder<BEAN,TARGET>Copyright © 2025. All rights reserved.