這是一個Ajax應用 Sample03a.zul 和Sample03b.zul 都是做同樣事情, 由於ZK 提供兩種編程方式,第一種是純XML格式,第二種是XML+JAVA格式:
Sample03a.zul
--------------------
<?xml version="1.0" encoding="UTF-8"?>
<zk>
<window id="win" title="ZK Window Property Control" width="400px" height="200px" border="normal" closable="true" sizable="true" >
<button label="Change Window Title" onClick="win.title="ZK application with Ajax""/>
</window>
</zk>
Hints : 由於.zul文件是XML文件,使用雙引號字符("")時,必須轉換成 " 才可以被XML解釋器正確地進行編譯
Sample03b.zul
--------------------
<?xml version="1.0" encoding="UTF-8"?>
<zk>
<window id="win" apply="inisoft.mo.gui.Sample03b"></window>
</zk>
Sample03b.java
--------------------
package inisoft.mo.gui;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Window;
/**
* @author Van Chan
*/
public class Sample03b extends GenericForwardComposer{
Window win;
Button btn;
EventListener btnListener;
public void doAfterCompose(Component comp)throws Exception
{
super.doAfterCompose(comp);
win.setTitle("ZK Window Property Control");
win.setWidth("400px");
win.setHeight("200px");
win.setBorder("normal");
win.setClosable(true);
win.setSizable(true);
btn=new Button();
btn.setLabel("Change Window Title");
addListener(btn);
win.appendChild(btn);
}
public void addListener(Button btn){
btnListener = new EventListener()
{
public void onEvent(Event event)throws Exception{
win.setTitle("ZK application with Java");
}
};
btn.addEventListener(Events.ON_CLICK, btnListener);
}
}