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

From Documentation
 
m (correct highlight (via JWB))
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
#REDIRECT [[ZK Developer's Reference/Data Binding/When to Save Data from UI Components to the Data Source]]
+
{{Old Version
 +
|url=http://books.zkoss.org/wiki/ZK_Developer's_Reference/Data_Binding
 +
|}}
 +
{{ZKDevelopersGuidePageHeader}}
 +
 
 +
Data Binding Manager is triggered by events, or users' activities. Thus, you must specify events in the ZUML annotation expression with <code>save-when</code> tag expression to tell Data Binding Manager when to save the attribute of the component into the data source.
 +
 
 +
<code><component-name attribute-name="@{bean-name.attribute-name,save-when='component-id.event-name'}"/></code>
 +
 
 +
 
 +
* <code>component-id</code> represents the ID of a UI component
 +
* <code>event-name</code> 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 "<code>value</code>" of <code>Textbox</code> "<code>firstName</code>" into "<code>person.firstName</code>" when the <code>Textbox</code> itself fires "<code>onChange</code>" 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;
 +
|}
 +
 
 +
{{ZKDevelopersGuidePageFooter}}

Latest revision as of 10:40, 19 January 2022

Stop.png This documentation is for an older version of ZK. For the latest one, please click here.

DocumentationZK Developer's GuideZK in DepthData BindingWhen to Save Data from UI Components to the Data Source
When to Save Data from UI Components to the Data Source


Stop.png This documentation is for an older version of ZK. For the latest one, please click here.


Data Binding Manager is triggered by events, or users' activities. Thus, you must specify events in the ZUML annotation expression with save-when tag expression to tell Data Binding Manager when to save the attribute of the component into the data source.

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


  • component-id represents the ID of a UI component
  • event-name 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 "value" of Textbox "firstName" into "person.firstName" when the Textbox itself fires "onChange" event.

<?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>

Version History

Last Update : 2022/01/19


Version Date Content
     



Last Update : 2022/01/19

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