Class CollaborationBinder.CollaborationBindingBuilderImpl<BEAN,​FIELDVALUE,​TARGET>

    • Method Detail

      • bind

        public Binder.Binding<BEAN,​TARGET> bind​(ValueProvider<BEAN,​TARGET> getter,
                                                      Setter<BEAN,​TARGET> setter)
        Description copied from interface: Binder.BindingBuilder
        Completes this binding using the given getter and setter functions representing a backing bean property. The functions are used to update the field value from the property and to store the field value to the property, respectively.

        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).

        Specified by:
        bind in interface Binder.BindingBuilder<BEAN,​FIELDVALUE>
        Overrides:
        bind in class Binder.BindingBuilderImpl<BEAN,​FIELDVALUE,​TARGET>
        Parameters:
        getter - the function to get the value of the property to the field, not null
        setter - the function to write the field value to the property or null if read-only
        Returns:
        the newly created binding
      • bind

        public Binder.Binding<BEAN,​TARGET> bind​(String propertyName)
        Description copied from interface: Binder.BindingBuilder
        Completes this binding by connecting the field to the property with the given name. The getter and setter of the property are looked up using a PropertySet.

        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).

        Specified by:
        bind in interface Binder.BindingBuilder<BEAN,​FIELDVALUE>
        Overrides:
        bind in class Binder.BindingBuilderImpl<BEAN,​FIELDVALUE,​TARGET>
        Parameters:
        propertyName - the name of the property to bind, not null
        Returns:
        the newly created binding
        See Also:
        Binder.BindingBuilder.bind(ValueProvider, Setter)
      • withNullRepresentation

        public Binder.BindingBuilder<BEAN,​TARGET> withNullRepresentation​(TARGET nullRepresentation)
        Description copied from interface: Binder.BindingBuilder
        Maps binding value null to given null representation and back to null when converting back to model value.
        Parameters:
        nullRepresentation - the value to use instead of null
        Returns:
        a new binding with null representation handling.