ITeye博客

ZK 事件

编程足球 · 2012-05-10 17:00 · ZK · Web前端 · Markdown

  1. ZK事件

zul代码如下


<window title="ZK Essentials" mode="overlapped" border="normal" width="250px">
	      <label id="lbl"/>World !	      
	      <!-- lbl.setValue(self.getLabel); -->
	      <button label="Hello " onClick="lbl.value = self.label"/>
	      <button label="Good-bye " onClick="lbl.value = self.label"/>
	</window>

界面如下:

生成的html主要代码如下:


<div id="tIuP0-cave" class="z-window-overlapped-cnt">
   <span id="tIuP1" class="z-label"></span>
   <span id="tIuP2" class="z-label">World ! </span>
   <button id="tIuP3" class="z-button-os" type="button">Hello </button>
   <button id="tIuP4" class="z-button-os" type="button">Good-bye </button>
</div>

可以知道 ZK enhanced XML parser 会给每个控件加上控件ID

点击 Hello 按钮时候,浏览器发起http请求:

服务器响应:

2. ZK 事件绑定在java代码中 At line 1, we declared: apply=controller class name so that the events fired within the window is all forwarded to the controller for event handling.

At line 2, we need to give the "Hello" button an ID so the controller would know which button fired during the onClick event.

  1. 定义 apply

<window id="win" title="ZK Essentials" border="normal" width="250px"   apply="demo.zkoss.SampleCtrl>
      <button id="helloBtn" label="Hello"/>
</window>

  1. 绑定 'event_name$component_id'

package demo.zkoss;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Window;
public class SampleCtrl extends GenericForwardComposer {
      Window win;
      public void onClick$helloBtn(){
            Button btn = new Button();
            btn.setLabel("World !");
            btn.setParent(win);
      }
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。