惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Archives - TechRepublic
MongoDB | Blog
MongoDB | Blog
量子位
博客园 - 叶小钗
罗磊的独立博客
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
MyScale Blog
MyScale Blog
GbyAI
GbyAI
Help Net Security
Help Net Security
Y
Y Combinator Blog
Engineering at Meta
Engineering at Meta
Hacker News - Newest:
Hacker News - Newest: "LLM"
Latest news
Latest news
H
Hacker News: Front Page
Blog — PlanetScale
Blog — PlanetScale
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
S
Schneier on Security
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
Recorded Future
Recorded Future
S
Securelist
博客园 - Franky
Application and Cybersecurity Blog
Application and Cybersecurity Blog
A
About on SuperTechFans
N
News and Events Feed by Topic
AI
AI
T
Tenable Blog
N
News | PayPal Newsroom
C
Cybersecurity and Infrastructure Security Agency CISA
V
V2EX - 技术
T
Threat Research - Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
L
LINUX DO - 热门话题
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google Online Security Blog
Google Online Security Blog
S
Security Affairs
Webroot Blog
Webroot Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园 - 三生石上(FineUI控件)
C
Comments on: Blog
G
GRAHAM CLULEY

博客园 - daniel-shen

精通EJB-概述 硬件基础知识大全 教程:关于XMLBeans的初步 在客户端进行xslt对xml的xuan渲染 jaxp笔记2007-4-17 6.ZK用户接口标记语言 5.事件的监听和处理 - daniel-shen - 博客园 3.zk体系结构 "tomcat启动分析"文章读后笔记 jdk5.0 范型说明 java 数组反射例子 HTML小技巧 MessageFormat初步 ResourceBundle 与locale的使用 jni中关于dll的装载问题 java线程-消费者vs生产者 HttpSessionBindingListener实现与应用 用Java Servlets 2.4实现过滤 加和不加java:comp/env/前缀有什么区别?
4.组件的生命周期
daniel-shen · 2007-04-17 · via 博客园 - daniel-shen

4.组件的生命周期
本章将讲解页面加载和更新的生命周期
页面加载的生命周期
    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 by the component will be
released by JVM's Garbage Collector.