From Documentation

Jump to: navigation, search

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

It can be very useful to associate a collection with a UI components, and Data Binding Manager will convert the collection into UI components accordingly.

  1. Prepare the data source of Collection
  2. Associate the collection with model attribute of those supported UI components, ex. Listbox, Grid, and Tree.
  3. Define a template of UI component
    1. Define a variable, whatever you want, to represent each instance in the Collection with self attribute.<component-name self="@{each='variable-name'}"/> The variable-name could only be seen by component-name and its child components.
    2. Associate UI components with the variable
      <component-name attribute-name="@{variable-name.attribute-name}"/>

In the following example, we demonstrate how to associate a collection with Listbox to display a list of persons.

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>

<window width="500px">
     //prepare the example persons List
		int count = 30;
		List persons = new ArrayList();
		for(int j= 0; j &lt; count; ++j) {
			Person personx = new Person();

	<listbox rows="4" model="@{persons}">
			<listheader label="First Name" width="100px" />
			<listheader label="Last Name" width="100px" />
			<listheader label="Full Name" width="100px" />
		<!-- define variable person here-->
		<listitem self="@{each='person'}">
				<textbox value="@{person.firstName}" />
				<textbox value="@{person.lastName}" />
			<listcell label="@{person.fullName}" />

Version History

Last Update : 2011/1/18

Version Date Content

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