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

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `class`
  `UiBinding.Binding`
  Binding allows us to have commit/auto-commit mode.
  `static class`
  `UiBinding.BooleanConverter`
  Converts the source value to a Boolean.
  `static class`
  `UiBinding.BoundTableModel`
  Implements table model binding, this is implemented as a class to allow additional features such as adding/removing rows
  `static class`
  `UiBinding.CheckBoxRadioSelectionAdapter<PropertyType>`
  Adapts a `com.codename1.ui.CheckBox` or `com.codename1.ui.RadioButton` to binding
  `static class`
  `UiBinding.ComponentAdapter<PropertyType, ComponentType>`
  Adapters can be extended to allow any component to bind to a property via a converter
  `static class`
  `UiBinding.DateConverter`
  Converts the source value to a Date.
  `static class`
  `UiBinding.DoubleConverter`
  Converts the source value to a Double.
  `static class`
  `UiBinding.FloatConverter`
  Converts the source value to a Float.
  `static class`
  `UiBinding.IntegerConverter`
  Converts the source value to an Integer.
  `static class`
  `UiBinding.LongConverter`
  Converts the source value to a Long.
  `static class`
  `UiBinding.MappingConverter`
  Maps values to other values for conversion in a similar way to a Map this is pretty useful for API's like picker where we have a list of Strings and we might want a list of other objects to match every string
  `static class`
  `UiBinding.ObjectConverter`
  Object converter can convert an object from one type to another e.g.
  `static class`
  `UiBinding.PickerAdapter<PropertyType>`
  Adapts a `com.codename1.ui.spinner.Picker` to binding
  `static class`
  `UiBinding.RadioListAdapter<PropertyType>`
  Adapts a set of `com.codename1.ui.RadioButton` to a selection within a list of values
  `static class`
  `UiBinding.StringConverter`
  Converts the source value to a String.
  `static class`
  `UiBinding.TextAreaAdapter<PropertyType>`
  Adapts a `com.codename1.ui.TextArea` (and it's subclass `com.codename1.ui.TextField` to binding
  `static class`
  `UiBinding.TextComponentAdapter<PropertyType>`
  Adapts a `com.codename1.ui.TextComponent` to binding

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `UiBinding()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `UiBinding.Binding`
  `bind(PropertyBase prop, Component cmp)`
  Binds the given property to the component using default adapters
  `UiBinding.Binding`
  `bind(PropertyBase prop, Component cmp, UiBinding.ComponentAdapter adapt)`
  Binds the given property to the component using a custom adapter class
  `UiBinding.Binding`
  `bind(PropertyBusinessObject obj, Container cnt)`
  Binds a hierarchy of Components to a business object by searching the tree and collecting the bindings.
  `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.
  `void`
  `bindInteger(Property<Integer, ? extends Object> prop, TextArea ta)`
  Changes to the text area are automatically reflected to the given property and visa versa
  `void`
  `bindString(Property<String, ? extends Object> prop, TextArea ta)`
  Changes to the text area are automatically reflected to the given property and visa versa
  `UiBinding.BoundTableModel`
  `createTableModel(CollectionProperty<? extends PropertyBusinessObject, ? extends Object> objects, PropertyBusinessObject prototype)`
  Creates a table model which is implicitly bound to the properties
  `UiBinding.BoundTableModel`
  `createTableModel(List<? extends PropertyBusinessObject> objects, PropertyBusinessObject prototype)`
  Creates a table model which is implicitly bound to the properties
  `boolean`
  `isAutoCommit()`
  Is auto-commit mode on by default see `#setAutoCommit(boolean)`
  `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
  `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...
  `static void`
  `unbind(PropertyBusinessObject po)`
  Unbinds all the properties within the business object

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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

    public UiBinding.Binding bind(PropertyBusinessObject obj, Container cnt)

    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

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

    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