The deferred Attribute and the onCreate Event

It is worth to notice that, if the onCreate event listener is written in zscript, the deferred option mentioned in the previous second becomes useless. It is because the onCreate event is sent when the page is loaded. In other words, all deferred zscript will be evaluated when the page is loaded if the onCreate event listener is written in zscript as shown below.

<window onCreate="init()">
...

Rather, it is better to rewrite it as

<window use="my.MyWindow">
...

Then, prepare MyWindow.java as shown below.

package my;
public class MyWindow extends Window {
    public void onCreate() { //to process the onCreate event    
...

If you prefer to do the initialization right after the component (and all its children) is created, you can implement the org.zkoss.zk.ui.ext.AfterCompose interface as shown below. Note: the afterCompose method of the AfterCompose interface is evaluated at the Component Creation phase, while the onCreate event is evaluated in the Event Processing Phase.

package my;
public class MyWindow extends Window implements org.zkoss.zk.ui.ext.AfterCompose {
    public void afterCompose() { //to initialize the window    
...