数据绑定管理器是被事件或者用户的活动触发的。因此,你必须使用load-when标签表达式在ZUML注释表达式内指定事件,以告诉数据绑定管理器何时从数据源加载数据至组件的属性。
<component-name attribute-name="@{bean-name.attribute-name, load-when='component-id.event-name'}"/>
component-id描述一个UI组件的ID。
event-name描述事件名称。
允许多重定义但需要依次调用。
在下面的例子中,一旦一个人的 first name 或 last name被修改,则fullname会被自动更新。
当id为firstName 或lastName 的Textbox的值被更改时,数据绑定管理器会从person.fullName重新加载数据至id为fullName的Label。换句话说,onChange事件会被触发。
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<window>
<zscript>
//prepare the example person object
Person person = new Person();
person.setFirstName("George");
person.setLastName("Bush");
</zscript>
<grid width="400px">
<rows>
<row> First Name:
<textbox id="firstName" value="@{person.firstName}"/>
</row>
<row> Last Name:
<textbox id="lastName" value="@{person.lastName}"/>
</row>
<row> Full Name:
<label id="fullName" value="@{person.fullName,
load-when='firstName.onChange,lastName.onChange'}"/>
</row>
</rows>
</grid>
</window>