|
Processing...
Description & Source Code
demo.zul
<window id="win" title="Car Inventory Editor" width="400px" border="normal"
apply="demo.getting_started.input.EditController">
<grid>
<rows>
<row>
Title:
<textbox id="titleTextbox" value="${win$composer.inventoryItem.title}"
constraint="no empty" />
</row>
<row>
Created Date (yyyy/MM/dd):
<datebox id="createdDatebox" value="${win$composer.inventoryItem.createdDate}"
format="yyyy/MM/dd" constraint="no empty" />
</row>
<row>
Bar Code:
<intbox id="barcodeIntbox" value="${win$composer.inventoryItem.barcode}"
format="000000" constraint="no empty,no negative" />
</row>
<row>
Unit Price:
<doublebox id="unitPriceDoublebox" value="${win$composer.inventoryItem.unitPrice}"
format=",###.#" constraint="no empty,no negative" />
</row>
<row>
Quantity:
<spinner id="quantitySpinner" value="${win$composer.inventoryItem.quantity}"
format=",###" constraint="no empty,min 0" />
</row>
<row>
Location (click location to edit):
<textbox id="locationTextbox" value="${win$composer.inventoryItem.location}"
inplace="true" />
</row>
</rows>
</grid>
<button id="submitButton" label="Submit" />
</window>
EditController.java
package demo.getting_started.input;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Doublebox;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.Spinner;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;
import demo.getting_started.CarService;
import demo.getting_started.CarServiceImpl;
import demo.getting_started.InventoryItem;
public class EditController extends SelectorComposer<Component> {
private static final long serialVersionUID = 1L;
private CarService carService = new CarServiceImpl();
private InventoryItem inventoryItem = new InventoryItem("1", "The Tumbler", new Date(), 654321, 29999.9,
30, "Southern Depository");
@Wire
private Window win;
@Wire
private Textbox titleTextbox;
@Wire
private Datebox createdDatebox;
@Wire
private Intbox barcodeIntbox;
@Wire
private Doublebox unitPriceDoublebox;
@Wire
private Spinner quantitySpinner;
@Wire
private Textbox locationTextbox;
public InventoryItem getInventoryItem() {
return inventoryItem;
}
@Listen("onChange = #titleTextbox")
public void changeTitle() {
String title = titleTextbox.getValue();
inventoryItem.setTitle(title);
showNotify("Changed to: " + title, titleTextbox);
}
@Listen("onChange = #createdDatebox")
public void changeCreatedDate() {
Date createdDate = createdDatebox.getValue();
inventoryItem.setCreatedDate(createdDate);
DateFormat formatter = new SimpleDateFormat(createdDatebox.getFormat());
showNotify("Changed to: " + formatter.format(createdDate), createdDatebox);
}
@Listen("onChange = #barcodeIntbox")
public void changeBarcode() {
Integer barcode = barcodeIntbox.getValue();
inventoryItem.setBarcode(barcode);
NumberFormat formatter = new DecimalFormat(barcodeIntbox.getFormat());
showNotify("Changed to: " + formatter.format(barcode), barcodeIntbox);
}
@Listen("onChange = #unitPriceDoublebox")
public void changeUnitPrice() {
Double unitPrice = unitPriceDoublebox.getValue();
inventoryItem.setUnitPrice(unitPrice);
NumberFormat formatter = new DecimalFormat(unitPriceDoublebox.getFormat());
showNotify("Changed to: " + formatter.format(unitPrice), unitPriceDoublebox);
}
@Listen("onChange = #quantitySpinner")
public void changeQuantity() {
Integer quantity = quantitySpinner.getValue();
inventoryItem.setQuantity(quantity);
NumberFormat formatter = new DecimalFormat(quantitySpinner.getFormat());
showNotify("Changed to: " + formatter.format(quantity), quantitySpinner);
}
@Listen("onChange = #locationTextbox")
public void changeLocation() {
String location = locationTextbox.getValue();
inventoryItem.setLocation(location);
showNotify("Changed to:" + location, locationTextbox);
}
@Listen("onClick = #submitButton")
public void submit() {
carService.store(inventoryItem);
showNotify("Saved", win);
}
private void showNotify(String msg, Component ref) {
Clients.showNotification(msg, "info", ref, "end_center", 2000);
}
}
CarService.java
package demo.getting_started;
import java.util.List;
public interface CarService {
/**
* Retrieve all cars in the car store.
* @return all cars.
*/
public List<Car> findAll();
/**
* Store or modify a car in car store.
*/
void store(Car car);
/**
* Store or modify a inventory item in car store.
*/
void store(InventoryItem inventoryItem);
/**
* Order cars.
*/
void order(List<OrderItem> orderItems);
/**
* Retrieve the root of car categories.
*/
Category getCarCategoriesRoot();
/**
* Count cars by filter.
*/
int countByFilter(String filter);
/**
* Query cars by filter.
*/
List<Car> queryByFilter(String filter);
}
InventoryItem.java
package demo.getting_started;
import java.util.Date;
public class InventoryItem {
private String inventoryId;
private String title;
private Date createdDate;
private int barcode;
private double unitPrice;
private int quantity;
private String location;
public InventoryItem(String inventoryId, String title, Date createdDate, int barcode, double unitPrice, int quantity, String location) {
this.inventoryId = inventoryId;
this.title = title;
this.createdDate = createdDate;
this.barcode = barcode;
this.unitPrice = unitPrice;
this.quantity = quantity;
this.location = location;
}
public String getInventoryId() {
return inventoryId;
}
public void setInventoryId(String inventoryId) {
this.inventoryId = inventoryId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public int getBarcode() {
return barcode;
}
public void setBarcode(int barcode) {
this.barcode = barcode;
}
public double getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(double unitPrice) {
this.unitPrice = unitPrice;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
}
Copyright © 2005-2025 Potix Corporation All rights reserved.
|
|
Processing... |