Binder

From Documentation
Revision as of 06:32, 8 February 2012 by Hawk (talk | contribs) (Created page with "{{ZKDevelopersReferencePageHeader}} The <javadoc>org.zkoss.bind.Binder</javadoc> is the key role to operate the whole data binding mechanism. When we apply a <javadoc> org.zko...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


The Binder is the key role to operate 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 all binders subscribe to a default desktop-scoped event queue, thus this 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(queueScope='session')">

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




Last Update : 2012/02/08

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