Envisage ZK 6: The Next Generation Data Binding System"

From Documentation
Line 44: Line 44:
  
 
==One way save only data binding==
 
==One way save only data binding==
*Save when UI component attribute changes
+
*Save when UI component attribute changes:
*Multiple save to different target beans
+
<source lang="java">
*Conditional save before/after executing different commands
+
<textbox value="@bind(save=vm.person.firstname)"/>
 +
</source>
 +
*Multiple save to property of different target beans
 +
<source lang="java">
 +
<textbox value="@bind(save={vm.person.firstname, vm.tmpperson.firstname})"/>
 +
</source>
 +
*Conditional save before executing command
 +
<source lang="java">
 +
<textbox value="@bind(save=vm.person.firstname before 'update')"/>
 +
</source>
 +
*Conditional save after  executing command
 +
<source lang="java">
 +
<textbox value="@bind(save=vm.person.firstname after 'delete'"/>
 +
</source>
 +
*Multiple conditional save before/after executing different/same commands
 +
<source lang="java">
 +
<textbox value="@bind(save={vm.selected.firstname before 'update', vm.newperson.firstname before 'add'}"/>
 +
</source>
  
 
==Initial data binding==
 
==Initial data binding==

Revision as of 07:12, 21 October 2011

DocumentationSmall Talks2011OctoberEnvisage ZK 6: The Next Generation Data Binding System
Envisage ZK 6: The Next Generation Data Binding System

Author
Henri Chen, Principal Engineer, Potix Corporation
Date
October 21, 2011
Version
ZK 6


Introduction

This is a whole new data binding system with new specifications and implementations. Based on the experiences learned from our version one data binder and feedbacks from users' and contributors' suggestions, we have cooked this easy to use, flexible, features rich new data binding system in ZK6.

Features

A whole new, clean annotation expression

  • Same Java style annotation expression in zul: The new ZK annotation is consistent with Java's annotation style. If you know the Java style, you know the ZK Style. For details, please refer to [link].
  • A set of collaborated annotations: ZK Bind use a set of annotations to make using data binding as intuitive and clear as possible.
    • @bind(...): used to bind data and command
    • @converter(...): used to specify converters along with parameters
    • @valiator(...): used to specify validators along with parameters
    • @form(...): used to bind a form.

Flexiable expressions as EL 2.2

  • ZK Bind accept EL 2.2 syntax expression that you can provide flexible operations easily.
  • Bind to bean properties, indexed properties, Map keys seamlessly.
  • Bind to component custom attributes automatically.
  • Bind to Spring, CDI, and Seam managed bean automatically.

One way load only data binding

  • Load when bean property changes
<label value="@bind(load=vm.person.fullname)"/>
  • Conditional load after executing commands
<label value="@bind(load=vm.person.firstname after 'update')"/>
  • Conditional load before executing commands
<label value="@bind(load=vm.person.firstname before 'delete')"/>
  • Conditional load before/after different commands (multiple options are allowed)
<label value="@bind(load={vm.person.firstname after 'update', vm.person.message after 'delete'})"/>

One way save only data binding

  • Save when UI component attribute changes:
<textbox value="@bind(save=vm.person.firstname)"/>
  • Multiple save to property of different target beans
<textbox value="@bind(save={vm.person.firstname, vm.tmpperson.firstname})"/>
  • Conditional save before executing command
<textbox value="@bind(save=vm.person.firstname before 'update')"/>
  • Conditional save after executing command
<textbox value="@bind(save=vm.person.firstname after 'delete'"/>
  • Multiple conditional save before/after executing different/same commands
<textbox value="@bind(save={vm.selected.firstname before 'update', vm.newperson.firstname before 'add'}"/>

Initial data binding

*Load when UI components are first added into the binding system

Two way data binding

*Short expression of both save and load bindings

Bind to any attributes of the UI components

*Bind symmetrically to all attributes of UI components

Event command binding

*Bridge ZK event to command *Simple command name invocation *Automatic event listener registration

Conditional binding on command

*Different binding for different commands

Template/Collection binding

*Binding on Listbox/Grid/Tree/Combobox *Local variable scope is limited to the container component *Support index property

Form binding

*Temporary form binding to avoid immediate polution on data bean *Submit a form in a whole *Conditional save for different commands

Automatic Java annotated data dependency tracking

*Controllable load on save *@NotifyChange to notify property changes *@DependsOn to specify property change dependency

Embedded validation cycle

*Bind validator by name or by EL expression *Embedded system Validator: provide commonly used validators that user can use directly by specify the name

Enhanced converter mechanism

*Bind converter by name or by EL expression *Embedded system Converters: provide commonly used converters that user can use directly by specify the name

GenericBindComposer

*Ease UI component tree, binder, and data source association *Each binder covers only the applied component tree *Inter-BindComposer communications

Bind on demand

*Support dynamically add/remove bindings by API. *Attatched components with binding annotations are automatically managed by the existing binder if covered. *Detached components that were managed by a binder are automatically removed from the management.

Support seamless MVVM design pattern

*You can now utilize MVVM design pattern to achieve "separation of data and logic from presentation" easily with the new ZK Bind data binding system. For details about how to apply MVVM design pattern with ZK Bind, please see this series of Smalltalks[link].

The Album Example with ZK Bind

This is an example "steal" from the article Presentation Model by Martin Fowler. The use case is simple, whenever an album is selected from the