Binds a field to a bean property represented by the given getter and
setter pair. The functions are used to update the field value from the
property and to store the field value to the property, respectively.
Use the
#forField(HasValue) overload instead if you want to
further configure the new binding.
Note: Not all
HasValue implementations support
passing
null as the value. For these the Binder will
automatically change
null to a null representation provided by
HasValue#getEmptyValue(). This conversion is one-way only, if you
want to have a two-way mapping back to
null, use
#forField(HasValue) and
BindingBuilder#withNullRepresentation(Object).
When a bean is bound with
Binder#setBean(BEAN), 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.
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.bind(nameField, Person::getName, Person::setName);
Note: when a
null setter is given the field will
be marked as read-only by invoking
HasValue#setReadOnly(boolean).