Home   Single Page

The zk Element

<zk>...</zk>

It is a special element used to aggregate other components. Unlike a real component (say, hbox or div), it is not part of the component tree being created. In other words, it doesn't represent any component. For example,

<window>
    <zk>    
        <textbox/>        
        <textbox/>        
    </zk>    
</window>

is equivalent to

<window>
    <textbox/>    
    <textbox/>    
</window>

Then, what is it used for?

Multiple Root Elements in a Page

Due to XML's syntax limitation, we can only specify one document root. Thus, if you have multiple root components, you must use zk as the document root to group these root components.

<?page title="Multiple Root"?>
<zk>
    <window title="First">    
    ...    
    </window>    
    <window title="Second" if="${param.secondRequired}">    
    ...    
    </window>    
</zk>

Iteration Over Versatile Components

The zk element, like components, supports the forEach attribute. Thus, you could use it to generate different type of components depending on the conditions. In the following example, we assume mycols is a collection of objects that have several members, isUseText(), isUseDate() and isUseCombo().

<window>
    <zk forEach="${mycols}">    
        <textbox if="${each.useText}"/>        
        <datebox if="${each.useDate}"/>        
        <combobox if="${each.useCombo}"/>        
    </zk>    
</window>

Attribute Name

Description

if

[Optional][Default: true]

Specifies the condition to evaluate this element.

unless

[Optional][Default: false]

Specifies the condition not to evaluate this element.

forEach

[Optional][Default: ignored]

It specifies a collection of objects, such that the zk element will be evaluated repeatedly against each object in the collection. If not specified or empty, this attribute is ignored. If non-collection object is specified, it is evaluated only once as if a single-element collection is specified.

switch

[Optional][Default: none]

Provide the context for mutually exclusive evaluation. The value specified in this attribute is called the switch condition.

The only allowed children are the zk elements.

case

[Optional][Default: none]

Provides an alternative within the switch evaluation.

If the value is a string starting and ending with slash, such as /a[p]*/, it is considered as a regular expression, which is used to match the switch condition.

You can specify multiple cases by separating them with comma.

choose

[Optional][Default: none]

Provide the context for mutually exclusive evaluation.

The only allowed children are the zk elements.

when

[Optional][Default: none]

Provides an alternative within the choose evaluation.

It is evaluated if the condition matches.