組件的生命周期
本章將講解頁面加載和更新的生命周期
頁面加載的生命周期
     zk需要4個步驟來加載和翻譯一張zuml頁面:
1.頁面的初始化
2.創建組件
   3.事件的處理
   4.rendering
下面分別詳細的介紹上述4個階段
    頁面初始化
在這個階段,zk啟動了init函數,如果沒有定義這樣的處理指示,則跳過。
對于每一個init處理指示都有一個class屬性,一個指定的類被創建,然后它的doInit方法被調用。這個類將會進行什么操作呢,當然,這取決于你應用的要求。
<?init class="myinit"?>
另一種指定處理指示的形式是像下面這樣定義zscript文件。然后,這個zscript文件將會在本階段解釋。
<?init zscript="/my/init.zs"?>
注意在這個階段,頁面還沒有放到桌面。
組件創建階段
在這個階段,zk加載器解釋zuml頁面。它進行組件的創建和初始化。分下面幾步進行。
1.對于每一個組件,檢查它的if和unless屬性來決定組件的有效性。如果是無效的,則它和它的子組件均被忽略。
2.在foreach屬性中指定了items的集合,zk對每一個item重復下面的步驟。
3.基于元素的名字創建組件,或者使用use屬性指定的類
4.按zuml頁面上指定屬性次序的初始化成員
5.解釋嵌套的元素,重復整個過程
6.如果組件繼承org.zkoss.zk.ext.AfterCompose接口,調用afterCompose函數。
7.在所有的子組件都創建后,onCreate事件被發送到這個組件,應用可以在之后初始化一些元素的內容。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 create 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.
    事件處理階段
在這個階段,zk為桌面的每個事件調用每個監聽器。
一個獨立的線程開始調用每一個監聽器,所以在不影響其他事件處理的情況下可以被掛起。
在處理的過程中,一個監聽器可能會觸發其他的事件,參考event listening and processing章節。
the rendering phase
在所有的事件處理了之后,zk renders這些組件成為一個規則的html頁面,然后將其發送到瀏覽器。
為了render組件,redraw方法被調用。在這個方法里面,一個組件的執行將不會改變組件的內容。
更新頁面的生命周期
zk au engine 處理zk請求需要3個步驟:處理請求,處理事件,rendering
zk au engine 將zk請求傳遞到隊列(一個桌面一個隊列)。因此,對于一個桌面,請求是被順序處理的。對于不同的桌面,請求是平行處理的。
請求處理階段
根據請求,zk au engine可能更新被影響的組件的內容,盡管在客戶端看來內容是一樣的。
然后將相應的事件提交到隊列。
事件處理階段
這個過程和“組件創建階段”相同。在一個獨立的線程中順序的對事件進行處理。
the rendering phase
在所有的事件被處理了以后,zk renders 影響的組件,創建相應的zk回應,然后將這些回應發送回客戶端。然后client engine更新dom tree.

模型
組件即使在同一張頁面里面也可能有多種不同的表現。這種觀念叫做mold。程序員可以通過使用component接口的setMold方法動態的改變mold。所有的組件都有一個名為default的mold。一些組件可能支持多個mold,如tabbox同時支持default和accordion。
<tabbox><!-- if not specified, the default mold is assumed. -->
<tabs>
<tab label="Default"/>
</tabs>
<tabpanels>
<tabpanel>
<tabbox mold="accordion">
<tabs>
<tab label="First Accordion"/>
<tab label="Second Accordion"/>
</tabs>
<tabpanels>
<tabpanel>The first panel.</tabpanel>
<tabpanel>The second panel.</tabpanel>
</tabpanels>
</tabbox>
</tabpanel>
</tabpanels>
</tabbox>
組件的垃圾回收
Unlike many component-based GUI, ZK has no destroy or close method for components. Like W3C
DOM, a component is removed from the browser as soon as it is detached from the page. It is
shown as soon as it is attached to the page.
More precisely, once a component is detached from a page, it is no longer managed by ZK. If the
application doesn't have any reference to it. The memory occupied