The Component Creation Phase

In this phase, ZK loader interprets an ZUML page. It creates and initializes components accordingly. It takes several steps as follows.

  1. For each element, it examines the if and unless attribute to decide whether it is effective. If not, the element and all of its child elements are ignored.

  2. If the forEach attribute is specified with a collection of items, ZK repeats the following steps for each item in the collection.

  3. Creates a component based on the element name, or by use of the class specified in the use attribute, if any.

  4. Initializes the members one-by-one based on the order that attributes are specified in the ZUML page.

  5. Interprets the nested elements and repeat the whole procedure.

  6. Invokes the afterCompose method if the component implements the org.zkoss.zk.ui.ext.AfterCompose interface[29].

  7. After all children are created, the onCreate event is sent to this component, such that application could initialize the content of some elements later. Notice that the onCreate events are posted for child components first.

Note: an developer can perform some application-specific initialization by listening to the onCreate event or implementing AfterCompose. AfterCompose is called in the Component Creation Phase, while the onCreate event is handled by an event listener.

An event listener is free to suspend and resume the execution (such as creating modal dialogs), while AfterCompose is a bit faster since no need to fork another thread.



[29] The step 3-5 is so-called composing. That is why AfterCompose is named.