Home   Single Page

UI コンポーネントからデータソースに何時格納するか

データバィンディングはイベントもしくはユーザーの活動により発動されます。このように、ZUML アノテーション表現の中で save-when タグでデータバィンディングマネージャーに何時、コンポーネントの属性からにデータソースデータを格納するかを知らせます。

<component-name attribute-name="@{bean-name.attribute-name, load-when='component-id.event-name ' } "/>

複数の定義も可能で、1つずつ順番に呼ばれます。

以下のサンプルでは、 データバィンディングマネージャーは firstName という Textbox の value 属性を Textbox そのものの"onChange" イベントが発生した時に " 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>