package tutorial.present; import java.util.List; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.select.SelectorComposer; import org.zkoss.zk.ui.select.annotation.*; import org.zkoss.zul.*; import tutorial.model.Car; import tutorial.service.CarService; import tutorial.service.CarServiceImpl; public class SearchController extends SelectorComposer<Component> { private static final long serialVersionUID = 1L; @Wire private Textbox keywordBox; @Wire private Listbox carListbox; @Wire private Label modelLabel; @Wire private Label makeLabel; @Wire private Label priceLabel; @Wire private Label descriptionLabel; @Wire private Image previewImage; private CarService carService = new CarServiceImpl(); @Listen("onClick = #searchButton") public void search(){ String keyword = keywordBox.getValue(); List<Car> result = carService.search(keyword); carListbox.setModel(new ListModelList<Car>(result)); } @Listen("onSelect = #carListbox") public void showDetail(){ Car selected = carListbox.getSelectedItem().getValue(); previewImage.setSrc(selected.getPreview()); modelLabel.setValue(selected.getModel()); makeLabel.setValue(selected.getMake()); priceLabel.setValue(selected.getPrice().toString()); descriptionLabel.setValue(selected.getDescription()); } }