Class FieldBinder

  • All Implemented Interfaces:
    java.io.Serializable

    public class FieldBinder
    extends java.lang.Object
    implements java.io.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 Summary

      Constructors 
      Constructor Description
      FieldBinder​(java.lang.Object design)
      Creates a new instance of LayoutFieldBinder.
      FieldBinder​(java.lang.Object design, java.lang.Class<?> classWithFields)
      Creates a new instance of LayoutFieldBinder.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean bindField​(Component instance)
      Tries to bind the given Component instance to a member field of the bind target.
      boolean bindField​(Component instance, java.lang.String localId)
      Tries to bind the given Component instance to a member field of the bind target.
      protected static java.util.List<java.lang.reflect.Field> getFields​(java.lang.Class<?> searchClass)
      Returns a list containing Field objects reflecting all the fields of the class or interface represented by this Class object.
      java.util.Collection<java.lang.String> getUnboundFields()
      Returns a collection of field names that are not bound.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FieldBinder

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

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

      • getUnboundFields

        public java.util.Collection<java.lang.String> getUnboundFields()
                                                                throws FieldBindingException
        Returns a collection of field names that are not bound.
        Returns:
        a collection of fields assignable to Component that are not bound
        Throws:
        FieldBindingException
      • 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,
                                 java.lang.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 java.util.List<java.lang.reflect.Field> getFields​(java.lang.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