-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Is any simple example on Master-detail CRUD?
Hi, drishtisv
I write a sample
index.zul
<zk> <window apply="ctrl.MyComposer2"> <hbox> <listbox id="listbox" width="200px" /> <grid id="grid" width="300px"> <columns> <column label="name" /> <column label="price" /> </columns> </grid> </hbox> </window> </zk>
MyComposer2.java
package ctrl; import java.util.*; import org.zkoss.zk.ui.*; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.*; public class MyComposer2 extends GenericForwardComposer { private Listbox listbox; private Grid grid; private ListModelList gridModel; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); grid.setRowRenderer(new RowRenderer() { @Override public void render(Row row, Object data) throws Exception { if (data == null) return; Product product = (Product) data; row.appendChild(new Label(product.getName())); row.appendChild(new Label("$" + product.getPrice())); } }); gridModel = new ListModelList(); grid.setModel(gridModel); listbox.setItemRenderer(new ListitemRenderer() { @Override public void render(Listitem item, Object data) throws Exception { if (data == null) return; Product product = (Product) data; item.setLabel(product.getName()); } }); Product p1 = new Product("CPU", 100); Product p2 = new Product("Memory", 50); Product p3 = new Product("Motherboard", 70); List<Product> list = new ArrayList<Product>(); list.add(p1); list.add(p2); list.add(p3); listbox.setModel(new ListModelList(list)); } public void onSelect$listbox(){ int index = listbox.getSelectedIndex(); ListModelList model = (ListModelList)listbox.getModel(); Product product = (Product) model.get(index); gridModel.clear(); gridModel.add(product); } private class Product{ private String name; private int price; public Product(String name, int price) { super(); this.name = name; this.price = price; } public String getName() { return name; } public int getPrice() { return price; } } }
or use databinding
refer to here
Thanks for reply
I don't want to use GenericForwardComposer. I seen the databinding example.
I am using iBATIS for ORM. I required a single entry of Master and multiple entries of details. When I click save button all entries of master-detail will be inserted into master and detail table. As we did it on Delphi/VB when i was using. I am confused how to do it on web based apps.
Hi all experts,
Anybody help me !!!!
Why is it "I don't want to use GenericForwardComposer"? This uses the MVC paradigm and is the best way to approach the problem. Your other choices are to use custom subclasses of Window, etc, and the "use" attribute in ZUL or code all your stuff in zscript. If you do the latter, you'll one day regret it. It's nice for some quick prototyping, but not something you really want as a production solution.
rv,
Welcome to ZK! You'll find a lot of great information on this forum - there are a lot of really helpful people here. I'd also encourage you to try out the forum's search function - it is a great resource.
As for the CRUD example, I would try here first.
Regards,
Todd
Asked: 2010-03-07 22:28:30 +0800
Seen: 2,045 times
Last updated: Jan 07 '11