Iterative Evaluation"

From Documentation
(Created page with '{{ZKDevelopersReferencePageHeader}} =Version History= {{LastUpdated}} {| border='1px' | width="100%" ! Version !! Date !! Content |- |   |   |   |} {{ZKDeveloper…')
 
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
 +
 +
=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,
 +
 +
<source lang="xml">
 +
<listbox>
 +
    <listitem label="${each}" forEach="Apple, Orange, Strawberry"/>
 +
</listbox>
 +
</source>
 +
 +
is equivalent to
 +
 +
<source lang="xml">
 +
<listbox>
 +
    <listitem label="Apple"/>
 +
    <listitem label="Orange"/>
 +
    <listitem label="Strawberry"/>
 +
</listbox>
 +
</source>
 +
 +
When ZK Loader iterates through items of the give collection, it will update two implicit objects: [[ZUML Reference/EL Expressions/Implicit Objects/each|each]] and [[ZUML Reference/EL Expressions/Implicit Objects/forEachStatus|forEachStatus]]. The each variable represents the item being iterated, while forEachStatus is an instance of <javadoc type="interface">org.zkoss.zk.ui.util.ForEachStatus</javadoc>, 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 [[ZUML Reference/ZUML/Elements/zk|zk]] element as shown below.
 +
 +
<source lang="xml">
 +
<zk forEach="${cond}">
 +
    ${each.name}
 +
    <textbox value="${each.value}"/>
 +
    <button label="Submit"/>
 +
</zk>
 +
</source>
 +
 +
The <code>zk</code> 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=
 
=Version History=

Revision as of 09:08, 7 December 2010


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.