Class UiBinding

java.lang.Object
com.codename1.properties.UiBinding

public class UiBinding extends Object

The binding framework can implicitly bind UI elements to properties, this allow seamless model to UI mapping. Most cases allow simple binding by just using the com.codename1.ui.Component) method to seamlessly update a property/component based on changes.

It contains the following base concepts:

  1. com.codename1.properties.UiBinding.ObjectConverter - a converter converts from one type to another. E.g. if we want a com.codename1.ui.TextArea to map to an Integer property we'd use an com.codename1.properties.UiBinding.IntegerConverter to indicate the desired destination value.

  2. com.codename1.properties.UiBinding.ComponentAdapter - takes two com.codename1.properties.UiBinding.ObjectConverter to convert to/from the component and property. It provides the API for event binding and value extraction/setting on the component.

  3. com.codename1.properties.UiBinding.Binding - the commit mode.

  4. com.codename1.ui.Component) - the bind helper methods allow us to bind a component easily without exposure to these complexities.

  • Constructor Details

    • UiBinding

      public UiBinding()
  • Method Details

    • unbind

      public static void unbind(PropertyBase prop)

      Allows us to unbind the property from binding, this is equivalent to calling com.codename1.properties.UiBinding.Binding#disconnect() on all bindings...

      Parameters
      • prop: the property
    • unbind

      public static void unbind(PropertyBusinessObject po)

      Unbinds all the properties within the business object

      Parameters
      • po: the business object
    • isAutoCommit

      public boolean isAutoCommit()

      Is auto-commit mode on by default see #setAutoCommit(boolean)

      Returns

      true if auto-commit is on

    • setAutoCommit

      public void setAutoCommit(boolean b)

      Default value for auto-commit mode, in auto-commit mode changes to the component/property are instantly reflected otherwise com.codename1.properties.UiBinding.CommitMode#commit() should be invoked explicitly

      Parameters
      • b: true to enable auto commit mode
    • bind

      Binds a hierarchy of Components to a business object by searching the tree and collecting the bindings. Components are associated with properties based on their name attribute

      Parameters
      • obj: the business object with the properties to bind

      • cnt: a container that will be recursed for binding

      Returns

      a Binding object that manipulates all of the individual bindings at once

    • bindGroup

      public UiBinding.Binding bindGroup(PropertyBase prop, Object[] values, Component... cmps)

      Binds the given property to the selected value from the set based on the multiple components. This is useful for binding multiple radio buttons to a single property value based on selection

      Parameters
      • prop: the property

      • values: the values that can be used

      • cmps: the components

      Returns

      a binding object that allows us to toggle auto commit mode, commit/rollback and unbind

    • bind

      public UiBinding.Binding bind(PropertyBase prop, Component cmp)

      Binds the given property to the component using default adapters

      Parameters
      • prop: the property

      • cmp: the component

      Returns

      a binding object that allows us to toggle auto commit mode, commit/rollback and unbind

    • bind

      Binds the given property to the component using a custom adapter class

      Parameters
      • prop: the property

      • cmp: the component

      • adapt: @param adapt an implementation of com.codename1.properties.UiBinding.ComponentAdapter that allows us to define the way the component maps to/from the property

      Returns

      a binding object that allows us to toggle auto commit mode, commit/rollback and unbind

    • createTableModel

      public UiBinding.BoundTableModel createTableModel(List<? extends PropertyBusinessObject> objects, PropertyBusinessObject prototype)

      Creates a table model which is implicitly bound to the properties

      Parameters
      • objects: list of business objects

      • prototype: the type by which we determine the structure of the table

      Returns

      a bound table model that can be used in the Table class

    • createTableModel

      public UiBinding.BoundTableModel createTableModel(CollectionProperty<? extends PropertyBusinessObject, ? extends Object> objects, PropertyBusinessObject prototype)

      Creates a table model which is implicitly bound to the properties

      Parameters
      • objects: list of business objects

      • prototype: the type by which we determine the structure of the table

      Returns

      a bound table model that can be used in the Table class

    • bindString

      public void bindString(Property<String, ? extends Object> prop, TextArea ta)

      Changes to the text area are automatically reflected to the given property and visa versa

      Parameters
      • prop: the property value

      • ta: the text area

      Deprecated

      this code was experimental we will use the more generic Adapter/bind framework

    • bindInteger

      public void bindInteger(Property<Integer, ? extends Object> prop, TextArea ta)

      Changes to the text area are automatically reflected to the given property and visa versa

      Parameters
      • prop: the property value

      • ta: the text area

      Deprecated

      this code was experimental we will use the more generic Adapter/bind framework