Gusti Arya
Gusti Arya

Reputation: 1301

Can't Retrieve Value from zk listbox

Let's say i have a listbox that contain ten items, and then i set five items for every page, so now the listbox have two pages

and the problem is everytime i want to get the value in listbox it only get five items instead ten items.

im using ListItemRenderer on My Listbox

below is my code :

AnnotationConfiguration config = new AnnotationConfiguration();
SessionFactory sessionFactory = config.configure().buildSessionFactory();

Session session = sessionFactory.openSession();
String str = "from Users";
Query q = session.createQuery(str);

List<Users> user = q.list();
session.close();
sessionFactory.close();

list.setModel(new ListModelList<Users>(user));
list.setItemRenderer(new ListitemRenderer() {

    @Override
    public void render(Listitem item, Object data, int index)
            throws Exception {
        Users user = (Users) data;
        item.setValue(user);

        new Listcell(user.getUsername()).setParent(item);
        new Listcell(user.getUserrole()).setParent(item);
    }
});

}

below my code to get the value :

String name ="";
String role ="";

Users user = new Users();
Listbox box = (Listbox) list.getFellow("win").getFellow("list");
List<Listitem> lists = box.getItems();

//membaca setiap row yang ada pada list
for(Listitem currentList : lists){

    List<Component> com = currentList.getChildren();

    //membaca setiap column pada row
    for (Component currentComp : com){
        Listcell lc = (Listcell) currentComp;
        if(lc.getColumnIndex() == 0){
            name = lc.getLabel();
            System.out.println("name = " + name);
        }

        if(lc.getColumnIndex()==1){
            role = lc.getLabel();
            System.out.println("role = " + role);
        }
    }

}

Upvotes: 0

Views: 1885

Answers (1)

Nabil A.
Nabil A.

Reputation: 3400

This is the correct behavior. The List is the View and the View
never has more then 5 Items as you discribed.

You want to get the Model so get the Model.

ListModelList lists = (ListModelList)box.getModel();

Upvotes: 1

Related Questions