org.zkoss.zkplus.databind
Class AnnotateDataBinder

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

public class AnnotateDataBinder
extends DataBinder

The DataBinder that reads ZUML annotations to create binding info.

You have two ways to annotate ZK components. For ZK data binding, you can use <a:bind> annotation expression or @{...} annotaion expression.

To use <a:bind> annotation expression, in the ZUML page you must declare the XML namespace, xmlns:a="http://www.zkoss.org/2005/zk/annotation" first. Then declare <a:bind> before component to make the annotation.

However, since ZK 2.4, you can choose to annotate directly on the component attribute with intuitive @{...} expression.

For example, the following annotation associates the attibute "value" of the component "textbox" to the bean's value "person.address.city".

<a:bind> way:

 <a:bind value="person.address.city"/>
 <textbox/>
 

@{...} way:

 <textbox value="@{person.address.city}"/>
 

The @{...} pattern tells the ZUML parser that this is for annotation.

You can put more metainfo inside the <a:bind> or @{...} so this DataBinder knows what to do. The complete format is like this:

<a:bind> way:

 <a:bind attrY="bean's value;[tag:expression]..."/>
 <componentX/>
 

@{...} way:

 <componentX attrY="@{bean's value,[tag='expression']...}"/>
 

This associates the componentX's attribute attrY to the bean's value. The bean's value is something in the form of beanid.field1.field2... You can either call DataBinder.bindBean(java.lang.String, java.lang.Object) to bind the beanid to a real bean object or you can neglect it and this DataBinder would try to find it from the variables map via (Component.getVariable(java.lang.String, boolean) method. That is, all those variables defined in zscript are accessible by this DataBinder. Note that you can choose either two formats of annotations as your will and you can even hybrid them together though it is not generally a good practice.

The tag:expression or tag='expression' is a generic form to bind more metainfo to the attrY of the componentX. The currently supported tags includes "load-when", "save-when", "access", "converter", "load-after"(since 3.6.1), and "save-after"(since 3.6.1).

Since:
2.4.0 Supporting @{...} annotations., 3.0.0 Supporting multiple events of save-when tag and validation phase.
Author:
Henri Chen
See Also:
AnnotateDataBinderInit, DataBinder, Serialized Form

Field Summary
 
Fields inherited from class org.zkoss.zkplus.databind.DataBinder
_collectionItemMap, _collectionOwnerMap, ARGS, NULLIFY, TEMPLATE, TEMPLATEMAP, VARNAME
 
Constructor Summary
AnnotateDataBinder(Component comp)
          Constructor that read all binding annotations in the components inside the specified component (inclusive).
AnnotateDataBinder(Component[] comps)
          Constructor that read all binding annotations of the given components array.
AnnotateDataBinder(Component[] comps, boolean defaultConfig)
          Constructor that read all binding annotations of the given component array.
AnnotateDataBinder(Component comp, boolean defaultConfig)
          Constructor that read all binding annotations in the components inside the specified component (inclusive).
AnnotateDataBinder(Desktop desktop)
          Constructor that read all binding annotations of the components inside the specified desktop.
AnnotateDataBinder(Desktop desktop, boolean defaultConfig)
          Constructor that read all binding annotations of the components inside the specified desktop.
AnnotateDataBinder(Page page)
          Constructor that read all binding annotations of the components inside the specified page.
AnnotateDataBinder(Page page, boolean defaultConfig)
          Constructor that read all binding annotations of the components inside the specified page.
 
Method Summary
 
Methods inherited from class org.zkoss.zkplus.databind.DataBinder
addBinding, addBinding, addBinding, addBinding, addBinding, addBinding, addCollectionItem, addCollectionItem, bindBean, existBinding, existsBindings, getAllBindings, getBinding, getBindingCollectionItem, getBindings, init, isDefaultConfig, loadAll, loadAttribute, loadComponent, loadPropertyAnnotation, removeBinding, saveAll, saveAttribute, saveComponent, setDefaultConfig, setupTemplateComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotateDataBinder

public AnnotateDataBinder(Desktop desktop)
Constructor that read all binding annotations of the components inside the specified desktop.

Parameters:
desktop - the ZUML desktop.

AnnotateDataBinder

public AnnotateDataBinder(Page page)
Constructor that read all binding annotations of the components inside the specified page.

Parameters:
page - the ZUML page.

AnnotateDataBinder

public AnnotateDataBinder(Component comp)
Constructor that read all binding annotations in the components inside the specified component (inclusive).

Parameters:
comp - the ZUML component.

AnnotateDataBinder

public AnnotateDataBinder(Component[] comps)
Constructor that read all binding annotations of the given components array.

Parameters:
comps - the Component array.
Since:
3.0.0

AnnotateDataBinder

public AnnotateDataBinder(Desktop desktop,
                          boolean defaultConfig)
Constructor that read all binding annotations of the components inside the specified desktop.

Parameters:
desktop - the ZUML desktop.
defaultConfig - whether load default binding configuration defined in lang-addon.xml

AnnotateDataBinder

public AnnotateDataBinder(Page page,
                          boolean defaultConfig)
Constructor that read all binding annotations of the components inside the specified page.

Parameters:
page - the ZUML page.
defaultConfig - whether load default binding configuration defined in lang-addon.xml

AnnotateDataBinder

public AnnotateDataBinder(Component[] comps,
                          boolean defaultConfig)
Constructor that read all binding annotations of the given component array.

Parameters:
comps - the Component array
defaultConfig - whether load default binding configuration defined in lang-addon.xml
Since:
3.0.0

AnnotateDataBinder

public AnnotateDataBinder(Component comp,
                          boolean defaultConfig)
Constructor that read all binding annotations in the components inside the specified component (inclusive).

Parameters:
comp - the ZUML component.
defaultConfig - whether load default binding configuration defined in lang-addon.xml


Copyright © 2005-2009 Potix Corporation. All Rights Reserved.