Can't display list in zul page

asked 2017-12-07 00:02:36 +0800

mutandaoscura gravatar image mutandaoscura
1 1

updated 2017-12-11 09:34:37 +0800

cor3000 gravatar image cor3000
3669 1 7
ZK Team

i have following code veicoloImp:

package model;

import java.util.LinkedList;
import java.util.List;

import java.sql.*;

public class veicoloImp implements veicoloServ {

List<veicolo> allAuto= new LinkedList<veicolo>();
public veicoloImp() {
    try {
        String url="jdbc:mysql://localhost:3306/odin";
        Connection conn=DriverManager.getConnection(url,"root","stage123");
        Statement stmt= conn.createStatement();
        ResultSet rs= stmt.executeQuery("SELECT *FROM vehiclemodelyear");
        veicolo vei;
            vei = new veicolo();

        }catch( SQLException | ClassNotFoundException e) 



public List<veicolo>findAll(){
    return allAuto;

public List<veicolo> search(String keyword){
    List<veicolo> result = new LinkedList<veicolo>();

    if (keyword==null || "".equals(keyword)){
        result = allAuto;
        for (veicolo c: allAuto){
            if (c.getModel().toLowerCase().contains(keyword.toLowerCase())
    return result;


package model;

import java.util.List;

public interface veicoloServ {
    public List<veicolo>findAll();
    public List<veicolo> search(String keyword);


package controller;

import org.zkoss.zul.*;
import org.zkoss.zul.ext.Selectable;

import java.util.List;
import java.util.Set;

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.zul.Label;
import org.zkoss.zul.Listbox;
import model.veicolo;
import model.veicoloServ;
import model.veicoloImp;

public class veicoloController extends SelectorComposer<Component> {

private static final long serialVersionUID = -1772685322161992019L;
private Textbox keywordBox;
private Listbox carListBox;
private Label modelLabel;
private Label makeLabel;
private Label yearLabel;

private veicoloServ carService = new veicoloImp();

@Listen("onClick = #searchButton")
public void search(){
    String keyword = keywordBox.getValue();
    List<veicolo> result = carService.search(keyword);
    carListBox.setModel(new ListModelList<veicolo>(result));

public void show(){
    Set<veicolo> selection=((Selectable<veicolo>)carListBox.getModel()).getSelection();
    if (selection!=null && !selection.isEmpty()){
        veicolo selected = selection.iterator().next();



package controller;

import java.util.List;
import org.zkoss.bind.annotation.*;
import model.*;

public class veicoloViewModel {
    private String keyword;

    private veicolo selectedCar;

    private veicoloServ carService = new veicoloImp();
    private veicoloServ all=new veicoloImp();
    private List<veicolo> allAuto=all.findAll();

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    public String getKeyword() {
        return keyword;

    public List<veicolo> getCarList(){
        return allAuto;


    public void setSelectedCar(veicolo selectedCar) {
        this.selectedCar = selectedCar;
    public veicolo getSelectedCar() {
        return selectedCar;

    public void search(){
        allAuto = carService.search(keyword);



<window title="Search" width="600px" border="normal"
viewModel="@id('vm') @init('controller.veicoloViewModel')">
<hbox align="center">
    <textbox value="@save(vm.keyword)" />
    <button label="Search"  onClick="@command('search')" />
<listbox rows="3" model="@load(vm.allAuto)" emptyMessage="No car found in the result"
        <listheader label="Year" />
        <listheader label="Model" />
        <listheader label="Make"/>
    <template name="model">
            <listcell label="@init(each.year)"></listcell>
            <listcell label="@init(each.model)"></listcell>
            <listcell label="@init(each.make)"></listcell>
<hlayout style="margin-top:20px" width="100%">
    <image width="250px" src="@load(vm.selectedCar.preview)" />
    <vlayout hflex="1">
        <label value="@load(vm.selectedCar.year)" />
        <label value="@load(vm.selectedCar.model)" />
        <label value="@load(vm.selectedCar.make)" />


when i start on server my list is empty

delete flag offensive retag edit


it's your getter what's wrong. use vm.carList or change your getter to getAllAuto

chillworld ( 2017-12-07 15:04:21 +0800 )edit

thx i change it to getAllAuto but i still have the same problem :(

mutandaoscura ( 2017-12-07 16:32:48 +0800 )edit

Ik don't know why you have posted the controller as you use MVVM, but if list is empty, check if your getter is invoked and print the size of it in logging

chillworld ( 2017-12-07 21:44:16 +0800 )edit

with a main class i invoke getallAuto and findAll to see if i get something and they return to console the same list ,as i expected,[model.veicolo@... ,model.veicolo@.etc]. I put a breakpoint to all get and debug from main,all is ok but if i try to debug from the project on server it skip breakpnt

mutandaoscura ( 2017-12-07 22:33:21 +0800 )edit

you are working with ZK8 or later? otherwise you need to add the BindComposer. if the logging doesn't work, the class is not loaded. So check if you are on the right zul page by altering the page, if you see the pages you are good. Any stacktraces in the logging of the server?

chillworld ( 2017-12-08 01:17:02 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-12-08 08:48:05 +0800

cooperkuo gravatar image cooperkuo

or change your getter to

link publish delete flag offensive edit
Your answer
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




Asked: 2017-12-07 00:02:36 +0800

Seen: 16 times

Last updated: Dec 11 '17