Iterative Evaluation

From Documentation
Revision as of 09:08, 7 December 2010 by Tomyeh (talk | contribs)


Iterative Evaluation


forEach

By default, ZK instantiates a component for each XML element. If you would like to generate a collection of components, you could specify the forEach attribute. For example,

<listbox>
    <listitem label="${each}" forEach="Apple, Orange, Strawberry"/>
</listbox>

is equivalent to

<listbox>
    <listitem label="Apple"/>
    <listitem label="Orange"/>
    <listitem label="Strawberry"/>
</listbox>

When ZK Loader iterates through items of the give collection, it will update two implicit objects: each and forEachStatus. The each variable represents the item being iterated, while forEachStatus is an instance of ForEachStatus, from which you could retrieve the index and the previous forEach, if any (nested iterations).

Apply forEach to Muliple Elements

If you have to iterate a collection of items for multiple XML elements, you could group them with the zk element as shown below.

<zk forEach="${cond}">
    ${each.name}
    <textbox value="${each.value}"/>
    <button label="Submit"/>
</zk>

The zk element is a special element used to group a set of XML element nested. ZK Loader won't create a component for it. Rather, ZK Loader interprets the forEach, if and unless attribute it might have.

Version History

Last Update : 2010/12/07


Version Date Content
     



Last Update : 2010/12/07

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