Binder

From Documentation

Stop.png This article is out of date, please refer to zk-mvvm-book/8.0/data_binding/binder for more up to date information.


The Binder is the key in the whole data binding mechanism. When we apply a BindComposer on a component, it will create a binder and pass component's and ViewModel's object reference to the binder.

Binder parses ZK bind annotations on ZULs to establish data binding relationship between components and ViewModel. It also synchronizes data between ZUL(View) and ViewModel based on the binding relationship and forwards events to ViewModel's command method.

Typically ViewModel is just a POJO. As it has no knowledge about others, a ViewModel can only communicate with another one by binder. The binder is like a broker and uses ViewModel's meta data(annotation) and methods to help it communicate with others. By default a binder subscribes to a desktop-scoped event queue, thus event queue is a common communication mechanism among binders. There are 2 features: global command binding and dynamic change notification that operate based on this mechanism.

Mvvm-binder.png

ZK also allows you to change default queue name and scope that a binder subscribes. You can separate binders into different groups by changing queue's name and scope upon your requirement.The syntax is as follows:

<window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('foo.MyViewModel')"
	binder="@init(queueName='myqueue')">


<window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('foo.MyViewModel')"
	binder="@init(value='xxx.MyBinder', queueScope='session')">

For available scopes, please refer ZK Developer's Reference/Event Handling/Event Queues.

For binder class customization(This feature is reserved for framework architect, NOT recommended for app developer!), your implementation must extends AnnotateBinder


Version History

Version Date Content
6.0.0 February 2012 The MVVM was introduced.




Last Update : 2022/07/08

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