public class UiBinding

  1. Object
  2. UiBinding

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 types

class UiBinding.ObjectConverterObject converter can convert an object from one type to another e.g. a String to an integer an array to a list model.
class UiBinding.StringConverterConverts the source value to a String.
class UiBinding.IntegerConverterConverts the source value to an Integer.
class UiBinding.DateConverterConverts the source value to a Date.
class UiBinding.LongConverterConverts the source value to a Long.
class UiBinding.FloatConverterConverts the source value to a Float.
class UiBinding.DoubleConverterConverts the source value to a Double.
class UiBinding.BooleanConverterConverts the source value to a Boolean.
class UiBinding.MappingConverterMaps 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
class UiBinding.ComponentAdapterAdapters can be extended to allow any component to bind to a property via a converter
class UiBinding.TextAreaAdapterAdapts a com.codename1.ui.TextArea (and it’s subclass com.codename1.ui.TextField to binding
class UiBinding.TextComponentAdapterAdapts a com.codename1.ui.TextComponent to binding
class UiBinding.CheckBoxRadioSelectionAdapterAdapts a com.codename1.ui.CheckBox or com.codename1.ui.RadioButton to binding
class UiBinding.RadioListAdapterAdapts a set of com.codename1.ui.RadioButton to a selection within a list of values
class UiBinding.PickerAdapterAdapts a com.codename1.ui.spinner.Picker to binding
class UiBinding.BoundTableModelImplements table model binding, this is implemented as a class to allow additional features such as adding/removing rows
class UiBinding.BindingBinding allows us to have commit/auto-commit mode.

Constructors

public UiBinding()

Methods

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

Inherited methods

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 PropertyBase
the property

unbind

public static void unbind(PropertyBusinessObject po)
Unbinds all the properties within the business object

Parameters

po PropertyBusinessObject
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 boolean
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 PropertyBusinessObject
the business object with the properties to bind
cnt Container
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 PropertyBase
the property
values Object[]
the values that can be used
cmps Component...
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 PropertyBase
the property
cmp Component
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 PropertyBase
the property
cmp Component
the component
adapt UiBinding.ComponentAdapter
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<? extends PropertyBusinessObject>
list of business objects
prototype PropertyBusinessObject
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 CollectionProperty<? extends PropertyBusinessObject, ? extends Object>
list of business objects
prototype PropertyBusinessObject
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)
Deprecated. this code was experimental we will use the more generic Adapter/bind framework
Changes to the text area are automatically reflected to the given property and visa versa

Parameters

prop Property<String, ? extends Object>
the property value
ta TextArea
the text area

bindInteger

public void bindInteger(Property<Integer, ? extends Object> prop, TextArea ta)
Deprecated. this code was experimental we will use the more generic Adapter/bind framework
Changes to the text area are automatically reflected to the given property and visa versa

Parameters

prop Property<Integer, ? extends Object>
the property value
ta TextArea
the text area