ZK Data Binding Part 1

 

Before seeing the ZK Data binding concept , first let us learn the for each attribute in zk

The following zul file is simple which has the list items

<?page title="Example1" contentType="text/html;charset=UTF-8"?>
<zk>
    <window title="Example1" border="normal">
        Example for "for each"
        <listbox>
            <listitem label="Apple" />
            <listitem label="Orange" />
            <listitem label="Strawberry" />
        </listbox>
    </window>
</zk>

image

The output can be expected if you use for each attribute as follows

 

<?page title="Example2" contentType="text/html;charset=UTF-8"?>
<zk>
    <window title="Example2" border="normal">
        Example for "for each"
        <listbox>
            <listitem label="${each}"
                forEach="Apple, Orange, Strawberry" />
        </listbox>
    </window>
</zk>

 

The forEach attribute is used to specify a collection of object such that the XML element it belongs will be evaluated repeatedly for each object of the collection.