Class 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:
-
com.codename1.properties.UiBinding.ObjectConverter- a converter converts from one type to another. E.g. if we want acom.codename1.ui.TextAreato map to anIntegerproperty we'd use ancom.codename1.properties.UiBinding.IntegerConverterto indicate the desired destination value. -
com.codename1.properties.UiBinding.ComponentAdapter- takes twocom.codename1.properties.UiBinding.ObjectConverterto convert to/from the component and property. It provides the API for event binding and value extraction/setting on the component. -
com.codename1.properties.UiBinding.Binding- the commit mode. -
com.codename1.ui.Component)- thebindhelper methods allow us to bind a component easily without exposure to these complexities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassBinding allows us to have commit/auto-commit mode.static classConverts the source value to a Boolean.static classImplements table model binding, this is implemented as a class to allow additional features such as adding/removing rowsstatic classAdapts acom.codename1.ui.CheckBoxorcom.codename1.ui.RadioButtonto bindingstatic classAdapters can be extended to allow any component to bind to a property via a converterstatic classConverts the source value to a Date.static classConverts the source value to a Double.static classConverts the source value to a Float.static classConverts the source value to an Integer.static classConverts the source value to a Long.static classMaps 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 stringstatic classObject converter can convert an object from one type to another e.g.static classAdapts acom.codename1.ui.spinner.Pickerto bindingstatic classAdapts a set ofcom.codename1.ui.RadioButtonto a selection within a list of valuesstatic classConverts the source value to a String.static classAdapts acom.codename1.ui.TextArea(and it's subclasscom.codename1.ui.TextFieldto bindingstatic classAdapts acom.codename1.ui.TextComponentto binding -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbind(PropertyBase prop, Component cmp) Binds the given property to the component using default adaptersbind(PropertyBase prop, Component cmp, UiBinding.ComponentAdapter adapt) Binds the given property to the component using a custom adapter classbind(PropertyBusinessObject obj, Container cnt) Binds a hierarchy of Components to a business object by searching the tree and collecting the bindings.bindGroup(PropertyBase prop, Object[] values, Component... cmps) Binds the given property to the selected value from the set based on the multiple components.voidbindInteger(Property<Integer, ? extends Object> prop, TextArea ta) Changes to the text area are automatically reflected to the given property and visa versavoidbindString(Property<String, ? extends Object> prop, TextArea ta) Changes to the text area are automatically reflected to the given property and visa versacreateTableModel(CollectionProperty<? extends PropertyBusinessObject, ? extends Object> objects, PropertyBusinessObject prototype) Creates a table model which is implicitly bound to the propertiescreateTableModel(List<? extends PropertyBusinessObject> objects, PropertyBusinessObject prototype) Creates a table model which is implicitly bound to the propertiesbooleanIs auto-commit mode on by default see#setAutoCommit(boolean)voidsetAutoCommit(boolean b) Default value for auto-commit mode, in auto-commit mode changes to the component/property are instantly reflected otherwisecom.codename1.properties.UiBinding.CommitMode#commit()should be invoked explicitlystatic voidunbind(PropertyBase prop) Allows us to unbind the property from binding, this is equivalent to callingcom.codename1.properties.UiBinding.Binding#disconnect()on all bindings...static voidUnbinds all the properties within the business object
-
Constructor Details
-
UiBinding
public UiBinding()
-
-
Method Details
-
unbind
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
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 explicitlyParameters
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
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
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 ofcom.codename1.properties.UiBinding.ComponentAdapterthat 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
Tableclass -
-
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
Tableclass -
-
bindString
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
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
-
-