When to Save Data from UI Components to the Data Source"

From Documentation
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{ZKDevelopersReferencePageHeader}}
+
#REDIRECT [[ZK Developer's Reference/MVVM/Data Binding]]
 
 
The Data Binding Manager is triggered by events or users' activities. Thus, you must specify events in the ZUML annotation expression with <tt>save-when</tt> tag expression to tell the Data Binding Manager when to save the attribute of the component into the data source.
 
 
 
<tt><component-name attribute-name="@{bean-name.attribute-name,save-when='component-id.event-name'}"/></tt>
 
 
 
 
 
* <tt>component-id</tt> represents the ID of a UI component
 
* <tt>event-name</tt> represents the event name
 
 
 
Multiple definition is allowed and would be called one by one.
 
 
 
In the following example, Data Binding Manager will save the attribute "<tt>value</tt>" of <tt>Textbox</tt> "<tt>firstName</tt>" into "<tt>person.firstName</tt>" when the <tt>Textbox</tt> itself fires "<tt>onChange</tt>" event.
 
 
 
<source lang="xml" >
 
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
 
 
 
<window width="500px">
 
<zscript><![CDATA[
 
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>
 
</source>
 
 
 
=Version History=
 
{{LastUpdated}}
 
{| border='1px' | width="100%"
 
! Version !! Date !! Content
 
|-
 
| &nbsp;
 
| &nbsp;
 
| &nbsp;
 
|}
 
 
 
{{ZKDevelopersReferencePageFooter}}
 

Latest revision as of 04:02, 10 February 2012