The apply Attribute

If you prefer the MVC (Model-View-Controller) approach, i.e., you prefer not to embed the handling codes in the window (the view), you can implement a class to initialize the window. The class must implement the org.zkoss.zk.ui.util.Composer interface.

import org.zkoss.zk.ui.util.Composer;
import org.zkoss.zul.Window;
public class MyComposer implements Composer {
    public void doAfterCompose(Component comp) {    
        ((Window)comp).setTitle("My Title"); //do whatever initialization you want        
            //comp is Window since we will specify it to a window later            
    }    
}

where assumes you have three event listeners, MyCreate, MyOK, and MyCancel. Refer to the Event section below for the explanation of event listeners.

Then, specify the class with the apply attribute as shown below.

<window apply="MyComposer">
...
</window>

The window is still created as an instance of org.zkoss.zul.Window, and it will be passed to the doAfterCompose method as the comp argument. Then, you can do any initialization you want.

If you want to apply multiple composers, separate them with comma. In addition, you can use an EL expression to return the class, its name, an instance of Composer, or a collection of Composer instances.

<window apply="MyComposer, AnotherComposer">
    <textbox apply="${c:mycomposer()}"/>    
</window>