Data Binding"

From Documentation
Line 4: Line 4:
  
  
'''ZKBIND'''  zkbind system's annotation name
+
= Annotation Attributes =
 +
 
 +
Here is the attribute list used in lang-addon.xml:
  
 
{| border="2"  
 
{| border="2"  
Line 30: Line 32:
 
|}
 
|}
  
 +
 +
= Example =
 +
 +
Let's take Textbox as an example to explain annotation attributes..
  
 
<source lang="xml">
 
<source lang="xml">
Line 59: Line 65:
  
 
</source>
 
</source>
 +
* We use <tt> <extends> </tt> to append data binding annotations based on original component definition.
 +
* '''ZKBIND'''  is zkbind system's annotation name. Currently this is the only value for <tt> <annotation-name> </tt>.
 +
* The <tt> <property-name> </tt> is the target property we want data binding to synchronize.
 +
* Because Textbox is a component for input, its access privilege is "both".
 +
* As the SAVE_EVENT is onChange,  you can find when your cursor focus on a Textbox is blured, Textbox's value is saved.
 +
* Here we use LOAD_REPLACEMENT for an issue related to "constraint" attribute. Because when we load textbox
 +
  
  

Revision as of 04:11, 9 February 2012

Data binding synchronizes data between View and ViewModel according to component definition's annotation. The annotation specifies when to save (or load) which attribute, how to convert, validate and render the data. It can be found in metainfo\zk\lang-addon.xml of zkbind.jar. Please refer to ZK Client-side Reference/Language Definition about how to configure language definition and its addon. If you want data binding can works on your newly-created component, you should define its own annotations.


Annotation Attributes

Here is the attribute list used in lang-addon.xml:

Attribute Name
Description
 ACCESS   Access privilege. The value can be "both", "save", or "load"(default value); default value is used if not specify.
 CONVERTER   System converter for special properties. e.g. SelectedItem in listbox. see ListboxSelectedItemConverter
 VALIDATOR   System validator for special properties.
 SAVE_EVENT   Save trigger event. It takes effect only when ACCESS attribute is "both" or "save".
 LOAD_EVENT   Load trigger event; It takes effect only when ACCESS attribute is "both" or "load".
 LOAD_REPLACEMENT   The replacement attribute for loading. It's used when there is a issue to load to original attribute.; e.g. value of textbox, it loads to "rawValue".
 LOAD_TYPE   Type of attribute for loading; e.g. rawValue of textbox is java.lang.String.
 SAVE_REPLACEMENT   The replacement attribute for saving. It's used when there is a issue to save to original attribute.; e.g. selectedItem of selectbox, it save the value selecteIndex via converter to the bean. (selectedItem is not existed in selectbox).
 RENDERER   A special renderer for binding


Example

Let's take Textbox as an example to explain annotation attributes..

	<component>
		<component-name>textbox</component-name>
		<extends>textbox</extends>
		<annotation>
			<annotation-name>ZKBIND</annotation-name>
			<property-name>value</property-name>
			<attribute>
				<attribute-name>ACCESS</attribute-name>
				<attribute-value>both</attribute-value>
			</attribute>
			<attribute>
				<attribute-name>SAVE_EVENT</attribute-name>
				<attribute-value>onChange</attribute-value>
			</attribute>
			<attribute>
				<attribute-name>LOAD_REPLACEMENT</attribute-name>
				<attribute-value>rawValue</attribute-value>
			</attribute>
			<attribute>
				<attribute-name>LOAD_TYPE</attribute-name>
				<attribute-value>java.lang.String</attribute-value>
			</attribute>
		</annotation>
	</component>
  • We use <extends> to append data binding annotations based on original component definition.
  • ZKBIND is zkbind system's annotation name. Currently this is the only value for <annotation-name> .
  • The <property-name> is the target property we want data binding to synchronize.
  • Because Textbox is a component for input, its access privilege is "both".
  • As the SAVE_EVENT is onChange, you can find when your cursor focus on a Textbox is blured, Textbox's value is saved.
  • Here we use LOAD_REPLACEMENT for an issue related to "constraint" attribute. Because when we load textbox


Version History

Last Update : 2012/02/09


Version Date Content
     




Last Update : 2012/02/09

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.