0

Master-detail CRUD

asked 2010-03-07 22:28:30 +0800

drishtisv gravatar image drishtisv
135 2

updated 2010-03-07 22:30:30 +0800

Is any simple example on Master-detail CRUD?

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2010-03-08 05:58:16 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2010-03-08 06:01:29 +0800

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

link publish delete flag offensive edit

answered 2010-03-08 07:53:52 +0800

drishtisv gravatar image drishtisv
135 2

updated 2010-03-10 05:46:08 +0800

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.

link publish delete flag offensive edit

answered 2010-03-10 08:13:49 +0800

drishtisv gravatar image drishtisv
135 2

updated 2010-03-10 08:14:20 +0800

Hi all experts,

Anybody help me !!!!

link publish delete flag offensive edit

answered 2010-03-10 09:15:32 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

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.

link publish delete flag offensive edit

answered 2010-03-10 23:44:21 +0800

drishtisv gravatar image drishtisv
135 2

Thank you very much clark

link publish delete flag offensive edit

answered 2011-01-06 00:58:40 +0800

rv gravatar image rv
6

hi guys!!!!
will u please give a MVC, CRUD full application with using database,,,i'm new with java and zk.....

link publish delete flag offensive edit

answered 2011-01-06 11:55:55 +0800

twiegand gravatar image twiegand
1807 3

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

link publish delete flag offensive edit

answered 2011-01-07 02:57:35 +0800

rv gravatar image rv
6

thnx Todd,,,

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-03-07 22:28:30 +0800

Seen: 2,045 times

Last updated: Jan 07 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More