The zscript Element

The zscript element is a special element to define the scripting codes that will be evaluated when a ZUML page is rendered. Typical use includes initialization and declaring global variables and methods.

Note: You cannot use EL expressions in zscript codes.

For example, the following example displays a different message each time the button is pressed.

<window title="Hello" border="normal">
    <button label="Say Hello" onClick="sayHello()"/>    
    <zscript>    
    int count = 0;    
    void sayHello() { //declare a global function    
        alert("Hello World! "+ ++count);        
    }    
    </zscript>    
</window>

Note: zscript is evaluated only once when the page is loaded. It is usually used to define methods and initial variables.