The Final Grid"

From Documentation
(init)
 
m
Line 1: Line 1:
 +
==The Final Grid==
 
In the '''initOperation''' method, <javadoc>org.zkoss.zul.Spinner</javadoc> and <javadoc>org.zkoss.zul.Button</javadoc> are created programmatically to allow end users to select and submit the quantity of the items to be purchased; the <javadoc>org.zkoss.zul.Cell</javadoc> is set as the parent component for these components. At line 14, we manually add an event listener to the button so we could verify whether the quantity from all orders combined does not exceed the quantity in stock.  
 
In the '''initOperation''' method, <javadoc>org.zkoss.zul.Spinner</javadoc> and <javadoc>org.zkoss.zul.Button</javadoc> are created programmatically to allow end users to select and submit the quantity of the items to be purchased; the <javadoc>org.zkoss.zul.Cell</javadoc> is set as the parent component for these components. At line 14, we manually add an event listener to the button so we could verify whether the quantity from all orders combined does not exceed the quantity in stock.  
 
<source lang="java">
 
<source lang="java">

Revision as of 10:23, 15 October 2010

The Final Grid

In the initOperation method, Spinner and Button are created programmatically to allow end users to select and submit the quantity of the items to be purchased; the Cell is set as the parent component for these components. At line 14, we manually add an event listener to the button so we could verify whether the quantity from all orders combined does not exceed the quantity in stock.

        private Cell initOperation(final Product prod){
		         Cell cell = new Cell();
		         final Spinner spinner = new Spinner(1);
		         spinner.setConstraint("min 1 max "+prod.getQuantity());
		         spinner.setParent(cell);
				
		         Button button = new Button("add");
		         button.setImage("/image/ShoppingCart-16x16.png");
		         button.setParent(cell);
				
		         final Label errorLb = new Label();
		         errorLb.setParent(cell);
				
		         button.addEventListener(ON_CLICK, new EventListener() {
			     public void onEvent(Event event) throws Exception {
			     ShoppingCartCtrl ctrl = ShoppingCartViewCtrl.getInstance(desktop);
			     try{
				 ctrl.addItem(prod, spinner.getValue());	
				 errorLb.setValue("");
			     }catch(WrongValueException e){
				 errorLb.setValue(e.getMessage());
			     }
			     }
			});
			return cell;
			}

The Final Grid

File:Product view.png