Java AJAX开发系列 - 3, ZK MVC
MVC架构在现在的很多系统中都有使用,ZK中同样也可以使用这种模式,如下是具体的例子:
View
<window id="win" title="ZK Essentials" border="normal" width="250px" apply="demo.zkoss.SampleCtrl">
<listbox id="orderLibox"
model="@{orderArea$composer.orders}" selectedItem="@{selectedX}">
<listhead>
<listheader label="info" />
<listheader label="description" />
<listheader label="Sub Total" />
</listhead>
<listitem self="@{each='order'}" value="@{order}">
<listcell
label="@{order, converter='demo.web.ui.OrderInfoTypeConverter'}" />
<listcell label="@{order.description}" />
<listcell label="@{order.total}" />
</listitem>
</listbox>
<button id="helloBtn" label="Hello"/>
</window>
Controller
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);
}
public List<Order> getOrders() {
List<Order> orders = getOrderDAO().findByUser(getCurrentUserId());
return orders;
}
}
Model
Order就是Model对象
ZK 5 Essentials 书中例子就包含了这方面的内容:
https://skydrive.live.com/?cid=56b433ad3d1871e3&id=56B433AD3D1871E3%21265
以上是完整工程下载,