|
Processing... Keep the keyword blank and click 'Search' can see all the cars.
Description & Source Code
demo.zul
<window title="Search" width="600px" border="normal" viewModel="@id('vm') @init('demo.getting_started.mvvm.SearchViewModel')"> <hlayout valign="middle"> Keyword: <textbox value="@bind(vm.keyword)" /> <button label="Search" iconSclass="z-icon-search" onClick="@command('search')" /> </hlayout> <listbox height="160px" model="@bind(vm.carList)" emptyMessage="No car found in the result" selectedItem="@bind(vm.selectedCar)" style="margin-top:10px"> <listhead> <listheader label="Model" /> <listheader label="Make" /> <listheader label="Price" width="20%"/> </listhead> <template name="model"> <listitem> <listcell label="@bind(each.model)"></listcell> <listcell label="@bind(each.make)"></listcell> <listcell>$<label value="@bind(each.price)" /></listcell> </listitem> </template> </listbox> <hlayout style="margin-top:20px" visible="@bind(not empty vm.selectedCar)"> <image src="@bind(vm.selectedCar.preview)" style="padding:10px" /> <vlayout> <hlayout> Model : <label value="@bind(vm.selectedCar.model)" style="font-weight:bold"/> </hlayout> <hlayout> Make : <label value="@bind(vm.selectedCar.make)" style="font-weight:bold"/> </hlayout> <hlayout> Price : <span>$<label value="@bind(vm.selectedCar.price)" style="font-weight:bold"/></span> </hlayout> <label value="@bind(vm.selectedCar.description)" /> </vlayout> </hlayout> </window> SearchViewModel.java
package demo.getting_started.mvvm; import java.util.List; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.NotifyChange; import demo.getting_started.tutorial.Car; import demo.getting_started.tutorial.CarService; import demo.getting_started.tutorial.CarServiceImpl; public class SearchViewModel { private String keyword; private List<Car> carList; private Car selectedCar; private CarService carService = new CarServiceImpl(); public void setKeyword(String keyword) { this.keyword = keyword; } public String getKeyword() { return keyword; } public List<Car> getCarList(){ return carList; } public void setSelectedCar(Car selectedCar) { this.selectedCar = selectedCar; } public Car getSelectedCar() { return selectedCar; } @Command @NotifyChange("carList") public void search(){ carList = carService.search(keyword); } } Car.java
package demo.getting_started.tutorial; public class Car { private Integer id; private String model; private String make; private String preview; private String description; private Integer price; public Car() { } public Car(Integer id, String model, String make, String description, String preview, Integer price) { this.id = id; this.model = model; this.make = make; this.preview = preview; this.description = description; this.price = price; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getMake() { return make; } public void setMake(String make) { this.make = make; } public String getPreview() { return preview; } public void setPreview(String preview) { this.preview = preview; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Integer getPrice() { return price; } public void setPrice(Integer price) { this.price = price; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } } CarService.java
package demo.getting_started.tutorial; import java.util.List; public interface CarService { /** * Retrieve all cars in the catalog. * @return all cars */ public List<Car> findAll(); /** * search cars according to keyword in name and company. * @param keyword for search * @return list of car that match the keyword */ public List<Car> search(String keyword); }
Copyright © 2005-2024 Potix Corporation All rights reserved.
|
Processing... |