org.zkoss.zkplus.databind
Class DataBinder

java.lang.Object
  extended by org.zkoss.zkplus.databind.DataBinder
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AnnotateDataBinder

public class DataBinder
extends java.lang.Object
implements java.io.Serializable

The DataBinder used for binding ZK UI component and the backend data bean.

Author:
Henri Chen
See Also:
Serialized Form

Field Summary
protected  java.util.Map<java.lang.String,CollectionItem> _collectionItemMap
           
protected  java.util.Map<java.lang.String,CollectionItem> _collectionOwnerMap
           
static java.lang.String ARGS
           
static java.lang.String LOAD_ON_SAVE_TRIGGER_COMPONENT
           
static java.lang.String NULLIFY
           
static java.lang.String TEMPLATE
           
static java.lang.String TEMPLATEMAP
           
static java.lang.String VARNAME
           
 
Constructor Summary
DataBinder()
           
 
Method Summary
 void addBinding(Component comp, java.lang.String attr, java.lang.String expr)
          Binding bean to UI component.
 void addBinding(Component comp, java.lang.String attr, java.lang.String expr, java.util.List<java.lang.String> loadWhenEvents, java.util.List<java.lang.String> saveWhenEvents, java.lang.String access, java.lang.String converter)
          Binding bean to UI component.
 void addBinding(Component comp, java.lang.String attr, java.lang.String expr, java.util.List<java.lang.String> loadWhenEvents, java.util.List<java.lang.String> saveWhenEvents, java.lang.String access, java.lang.String converter, java.util.Map<java.lang.Object,java.lang.Object> args, java.util.List<java.lang.String> loadAfterEvents, java.util.List<java.lang.String> saveAfterEvents)
          Binding bean to UI component.
 void addBinding(Component comp, java.lang.String attr, java.lang.String expr, java.util.List<java.lang.String> loadWhenEvents, java.lang.String saveWhenEvent, java.lang.String access, java.lang.String converter)
          Binding bean to UI component.
 void addBinding(Component comp, java.lang.String attr, java.lang.String expr, java.lang.String[] loadWhenEvents, java.lang.String[] saveWhenEvents, java.lang.String access, java.lang.String converter)
          Binding bean to UI component.
 void addBinding(Component comp, java.lang.String attr, java.lang.String expr, java.lang.String[] loadWhenEvents, java.lang.String saveWhenEvent, java.lang.String access, java.lang.String converter)
          Binding bean to UI component.
 void addCollectionItem(java.lang.Class item, java.lang.Class owner, CollectionItem decor)
          Adds a CollectionItem for the specified item and owner component; e.g.
 void bindBean(java.lang.String beanid, java.lang.Object bean)
          Bind a real bean object to the specified beanid.
 boolean existBinding(Component comp, java.lang.String attr)
          Whether this component and attribute associated with a binding.
 boolean existsBindings(Component comp)
          Whether this component associated with any bindings.
 java.util.Collection<Binding> getAllBindings()
          Return all Bindings covered by this DataBinder
 Binding getBinding(Component comp, java.lang.String attr)
          Given component and attr, return the associated Binding.
protected  CollectionItem getBindingCollectionItem(Component comp)
          Returns a CollectionItem by the comp accordingly.
 java.util.Collection<Binding> getBindings(Component comp)
          Given component, return the associated list of Bindings.
protected  void init()
           
 boolean isDefaultConfig()
          Whether use the default binding configuration.
 boolean isLoadOnSave()
          Returns whether this DataBinder shall do load-on-save automatically(default is true).
 void loadAll()
          Load all value from data beans to UI components.
 void loadAttribute(Component comp, java.lang.String attr)
          Load value from the data bean property to a specified attribute of the UI component.
 void loadComponent(Component comp)
          Load values from the data bean properties to all attributes of a specified UI component.
protected  java.lang.Object[] loadPropertyAnnotation(Component comp, java.lang.String propName, java.lang.String bindName)
           
 void removeBinding(Component comp, java.lang.String attr)
          Remove the binding associated with the attribute of the component.
 void saveAll()
          Save all values from UI components to beans.
 void saveAttribute(Component comp, java.lang.String attr)
          Save value from a specified attribute of the UI component to a data bean property.
 void saveComponent(Component comp)
          Save values from all attributes of a specified UI component to data bean properties.
 void setDefaultConfig(boolean b)
          Whether use the default binding configuration.
 void setLoadOnSave(boolean b)
          Sets whether this DataBinder shall do load-on-save automatically.
 void setupTemplateComponent(Component comp, java.lang.Object owner)
          Sets up the specified comp and its decendents to be as template (or not)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOAD_ON_SAVE_TRIGGER_COMPONENT

public static final java.lang.String LOAD_ON_SAVE_TRIGGER_COMPONENT
See Also:
Constant Field Values

NULLIFY

public static final java.lang.String NULLIFY
See Also:
Constant Field Values

ARGS

public static final java.lang.String ARGS
See Also:
Constant Field Values

VARNAME

public static final java.lang.String VARNAME
See Also:
Constant Field Values

TEMPLATEMAP

public static final java.lang.String TEMPLATEMAP
See Also:
Constant Field Values

TEMPLATE

public static final java.lang.String TEMPLATE
See Also:
Constant Field Values

_collectionItemMap

protected java.util.Map<java.lang.String,CollectionItem> _collectionItemMap

_collectionOwnerMap

protected java.util.Map<java.lang.String,CollectionItem> _collectionOwnerMap
Constructor Detail

DataBinder

public DataBinder()
Method Detail

setLoadOnSave

public void setLoadOnSave(boolean b)
Sets whether this DataBinder shall do load-on-save automatically.

Parameters:
b - true to have this DataBinder shall do load-on-save automatically.
Since:
5.0.4

isLoadOnSave

public boolean isLoadOnSave()
Returns whether this DataBinder shall do load-on-save automatically(default is true).

Returns:
whether this DataBinder shall do load-on-save automatically(default is true).
Since:
5.0.4

addBinding

public void addBinding(Component comp,
                       java.lang.String attr,
                       java.lang.String expr)
Binding bean to UI component. This is the same as addBinding(Component comp, String attr, String expr, (List)null, (List)null, (String)null, (String)null).

Parameters:
comp - The component to be associated.
attr - The attribute of the component to be associated.
expr - The expression to associate the data bean.

addBinding

public void addBinding(Component comp,
                       java.lang.String attr,
                       java.lang.String expr,
                       java.lang.String[] loadWhenEvents,
                       java.lang.String saveWhenEvent,
                       java.lang.String access,
                       java.lang.String converter)
Binding bean to UI component.

Parameters:
comp - The component to be associated.
attr - The attribute of the component to be associated.
expr - The expression to associate the data bean.
loadWhenEvents - The event list when to load data.
saveWhenEvent - The event when to save data.
access - In the view of UI component: "load" load only, "both" load/save, "save" save only when doing data binding. null means using the default access natural of the component. e.g. Label.value is "load", but Textbox.value is "both".
converter - The converter class used to convert classes between component and the associated bean. null means using the default class conversion method.

addBinding

public void addBinding(Component comp,
                       java.lang.String attr,
                       java.lang.String expr,
                       java.lang.String[] loadWhenEvents,
                       java.lang.String[] saveWhenEvents,
                       java.lang.String access,
                       java.lang.String converter)
Binding bean to UI component.

Parameters:
comp - The component to be associated.
attr - The attribute of the component to be associated.
expr - The expression to associate the data bean.
loadWhenEvents - The event list when to load data.
saveWhenEvents - The event when to save data.
access - In the view of UI component: "load" load only, "both" load/save, "save" save only when doing data binding. null means using the default access natural of the component. e.g. Label.value is "load", but Textbox.value is "both".
converter - The converter class used to convert classes between component and the associated bean. null means using the default class conversion method.
Since:
3.0.0

addBinding

public void addBinding(Component comp,
                       java.lang.String attr,
                       java.lang.String expr,
                       java.util.List<java.lang.String> loadWhenEvents,
                       java.lang.String saveWhenEvent,
                       java.lang.String access,
                       java.lang.String converter)
Binding bean to UI component.

Parameters:
comp - The component to be associated.
attr - The attribute of the component to be associated.
expr - The expression to associate the data bean.
loadWhenEvents - The event list when to load data.
saveWhenEvent - The event when to save data.
access - In the view of UI component: "load" load only, "both" load/save, "save" save only when doing data binding. null means using the default access natural of the component. e.g. Label.value is "load", but Textbox.value is "both".
converter - The converter class used to convert classes between component and the associated bean. null means using the default class conversion method.

addBinding

public void addBinding(Component comp,
                       java.lang.String attr,
                       java.lang.String expr,
                       java.util.List<java.lang.String> loadWhenEvents,
                       java.util.List<java.lang.String> saveWhenEvents,
                       java.lang.String access,
                       java.lang.String converter)
Binding bean to UI component.

Parameters:
comp - The component to be associated.
attr - The attribute of the component to be associated.
expr - The expression to associate the data bean.
loadWhenEvents - The event list when to load data.
saveWhenEvents - The event list when to save data.
access - In the view of UI component: "load" load only, "both" load/save, "save" save only when doing data binding. null means using the default access natural of the component. e.g. Label.value is "load", but Textbox.value is "both".
converter - The converter class used to convert classes between component and the associated bean. null means using the default class conversion method.
Since:
3.0.0

addBinding

public void addBinding(Component comp,
                       java.lang.String attr,
                       java.lang.String expr,
                       java.util.List<java.lang.String> loadWhenEvents,
                       java.util.List<java.lang.String> saveWhenEvents,
                       java.lang.String access,
                       java.lang.String converter,
                       java.util.Map<java.lang.Object,java.lang.Object> args,
                       java.util.List<java.lang.String> loadAfterEvents,
                       java.util.List<java.lang.String> saveAfterEvents)
Binding bean to UI component.

Parameters:
comp - The component to be associated.
attr - The attribute of the component to be associated.
expr - The expression to associate the data bean.
loadWhenEvents - The event list when to load data.
saveWhenEvents - The event list when to save data.
access - In the view of UI component: "load" load only, "both" load/save, "save" save only when doing data binding. null means using the default access natural of the component. e.g. Label.value is "load", but Textbox.value is "both".
converter - The converter class used to convert classes between component and the associated bean. null means using the default class conversion method.
args - generic argument map for each binding.
loadAfterEvents - the event list when to load data after.
saveAfterEvents - the event list when to save data after.
Since:
3.6.1

removeBinding

public void removeBinding(Component comp,
                          java.lang.String attr)
Remove the binding associated with the attribute of the component.

Parameters:
comp - The component to be removed the data binding association.
attr - The attribute of the component to be removed the data binding association.

getBinding

public Binding getBinding(Component comp,
                          java.lang.String attr)
Given component and attr, return the associated Binding.

Parameters:
comp - the concerned component
attr - the concerned attribute

getBindings

public java.util.Collection<Binding> getBindings(Component comp)
Given component, return the associated list of Bindings.

Parameters:
comp - the concerned component

getAllBindings

public java.util.Collection<Binding> getAllBindings()
Return all Bindings covered by this DataBinder

Returns:
all Bindings covered by this DataBinder.
Since:
3.5.2

existsBindings

public boolean existsBindings(Component comp)
Whether this component associated with any bindings.


existBinding

public boolean existBinding(Component comp,
                            java.lang.String attr)
Whether this component and attribute associated with a binding.


isDefaultConfig

public boolean isDefaultConfig()
Whether use the default binding configuration.


setDefaultConfig

public void setDefaultConfig(boolean b)
Whether use the default binding configuration.


bindBean

public void bindBean(java.lang.String beanid,
                     java.lang.Object bean)
Bind a real bean object to the specified beanid. You might not need to call this method because this DataBinder would look up the variable via the Component.getAttributeOrFellow(java.lang.String, boolean) method if it cannot find the specified bean via the given beanid.

Parameters:
beanid - The bean id used in data binding.
bean - The real bean object to be associated with the bean id.

loadAttribute

public void loadAttribute(Component comp,
                          java.lang.String attr)
Load value from the data bean property to a specified attribute of the UI component.

Parameters:
comp - the UI component to be loaded value.
attr - the UI component attribute to be loaded value.

saveAttribute

public void saveAttribute(Component comp,
                          java.lang.String attr)
Save value from a specified attribute of the UI component to a data bean property.

Parameters:
comp - the UI component used to save value into backend data bean.
attr - the UI component attribute used to save value into backend data bean.

loadComponent

public void loadComponent(Component comp)
Load values from the data bean properties to all attributes of a specified UI component.

Parameters:
comp - the UI component to be loaded value.

saveComponent

public void saveComponent(Component comp)
Save values from all attributes of a specified UI component to data bean properties.

Parameters:
comp - the UI component used to save value into backend data bean.

loadAll

public void loadAll()
Load all value from data beans to UI components.


saveAll

public void saveAll()
Save all values from UI components to beans.


loadPropertyAnnotation

protected java.lang.Object[] loadPropertyAnnotation(Component comp,
                                                    java.lang.String propName,
                                                    java.lang.String bindName)

init

protected void init()

addCollectionItem

public void addCollectionItem(java.lang.Class item,
                              java.lang.Class owner,
                              CollectionItem decor)
Adds a CollectionItem for the specified item and owner component; e.g. Listitem and Listbox, Row and Grid, Comoboitem and Combobox.

Parameters:
item - the item class
owner - the owner class
decor - the associated CollectionItem decorator
Since:
3.0.5
See Also:
CollectionItem

getBindingCollectionItem

protected CollectionItem getBindingCollectionItem(Component comp)
Returns a CollectionItem by the comp accordingly.

Since:
3.0.0
See Also:
CollectionItem

setupTemplateComponent

public void setupTemplateComponent(Component comp,
                                   java.lang.Object owner)
Sets up the specified comp and its decendents to be as template (or not)



Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo