Class FieldBinder

  • All Implemented Interfaces:
    Serializable

    public class FieldBinder
    extends Object
    implements Serializable
    Binder utility that binds member fields of a design class instance to given component instances. Only fields of type Component are bound
    Since:
    7.4
    Author:
    Vaadin Ltd
    See Also:
    Serialized Form
    • Constructor Detail

      • FieldBinder

        public FieldBinder​(Object design)
                    throws IntrospectionException
        Creates a new instance of LayoutFieldBinder.
        Parameters:
        design - the design class instance containing the fields to bind
        Throws:
        IntrospectionException - if the given design class can not be introspected
      • FieldBinder

        public FieldBinder​(Object design,
                           Class<?> classWithFields)
                    throws IntrospectionException
        Creates a new instance of LayoutFieldBinder.
        Parameters:
        design - the instance containing the fields
        classWithFields - the class which defines the fields to bind
        Throws:
        IntrospectionException - if the given design class can not be introspected
    • Method Detail

      • bindField

        public boolean bindField​(Component instance)
        Tries to bind the given Component instance to a member field of the bind target. The name of the bound field is constructed based on the id or caption of the instance, depending on which one is defined. If a field is already bound (not null), FieldBindingException is thrown.
        Parameters:
        instance - the instance to be bound to a field
        Returns:
        true on success, otherwise false
        Throws:
        FieldBindingException - if error occurs when trying to bind the instance to a field
      • bindField

        public boolean bindField​(Component instance,
                                 String localId)
        Tries to bind the given Component instance to a member field of the bind target. The fields are matched based on localId, id and caption.
        Parameters:
        instance - the instance to be bound to a field
        localId - the localId used for mapping the field to an instance field
        Returns:
        true on success
        Throws:
        FieldBindingException - if error occurs when trying to bind the instance to a field
      • getFields

        protected static List<Field> getFields​(Class<?> searchClass)
        Returns a list containing Field objects reflecting all the fields of the class or interface represented by this Class object. The fields in superclasses are excluded.
        Parameters:
        searchClass - the class to be scanned for fields
        Returns:
        the list of fields in this class