Single Page


The variables element

It defines a set of variables. It is equivalent to the setVariable method of Component, if it has a parent component, and Page, if it is declared at the page level.

As depicted below, variables is convenient to assign variables without programming.

<window>
    <variables rich="simple" simple="intuitive"/>    
</window>

It is equivalent to

<window>
    <zscript>    
        self.setVariable("rich", "simple", false);        
        self.setVariable("simple", "intuitive", false);        
    </zscript>    
</window>

Of course, you can specify EL expressions for the values.

<window>
    <window id="w" title="Test">    
        <variables title="${w.title}"/>        
        1: ${title}        
    </window>    
    2: ${title}    
</window>

Like Component's setVariable, you can control whether to declare variables local to the current ID space as follows. If not specified, local="false" is assumed.

<variables simple="rich" local="true"/>

The List and Map Values with the composite Attribute

By default, the value is assigned to the variable directly after evaluating EL expressions, if any. For example, "apple, ${more}" is evaluated to "apple, orange", if more is "orange", and assigned to the variable.

If you want to specify a list of values, you can specify the composite attribute with list as follows.

<variables simple="apple, ${more}" composite="list"/>

Then, it is converted to a list with two elements. The first element is "apple" and the second "orange".

If you want to specify a map of values, you can specify the composite attribute with map as follows.

<variables simple="juice=apple, flavor=${more}" composite="map"/>

Then, it is converted to a map with two entries. The first entry is ("juice", "apple") and the second ("flavor", "orange").

The null Value

In the following example, var is an empty string.

<variables var=""/>

To define a variable with the null value, use the following statement.

<variables var="${null}"/>

Assign a Variable with a Reserved Name

To assign a variable with a reserved name, say, forEach, you have to specify a namespace (which can be anything but ZK namespace) as follows.

<variables m:forEach="a value" xmlns:m="http://whatever.com"/>

Then, forEach will be considered as a variable rather than the iterative condition.