数据绑定管理器是被事件或者用户的活动触发的。因此,你必须使用save-when标签表达式在ZUML注释表达式内指定事件,以告诉数据绑定管理器何时将组件属性值保存至数据源。
<component-name attribute-name="@{bean-name.attribute-name,load-when='component-id.event-name'}"/>
component-id描述一个UI组件的ID。
event-name描述事件名称。
允许多重定义但需要依次调用。
在下面的例子中,当Textbox自身触发了"onChange"事件时,数据绑定管理器会将Textbox "firstName"的属性"value"保存至"person.firstName"。
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<window width="500px">
<zscript>
Person person = new Person();
person.setFirstName("Bill");
person.setLastName("Gates");
</zscript>
<listbox>
<listhead>
<listheader label="First Name" width="100px"/>
<listheader label="Last Name" width="100px"/>
<listheader label="Full Name" width="100px"/>
</listhead>
<listitem>
<listcell>
<textbox id="firstName" value="@{person.firstName, save-when='self.onChange'}"/>
</listcell>
<listcell>
<textbox id="lastName" value="@{person.lastName, save-when='self.onChange'}"/>
</listcell>
<listcell label="@{person.fullName}"/>
</listitem>
</listbox>
</window>