How to clear ListBox? (ZK)



I have very simple question. I amazed, that couldn’t find answer. How can I make total clearing of ListBox (org.zkoss.zul.ListBox) in ZK Framework?

Answer

Code below clears the Listbox, but maybe causes problems, if a model is used :

lb.getItems().clear();

Code below clears the selection :

lb.clearSelection();

Code below sets a new model, deletes the old one and all items. The Listbox will be empty if the model is empty

lb.setModel(model);

If you like to get a new set of Items, the last one should be the best.
If you have a List of them use :

lb.setModel(new ListModelList<>(myList)); 


Source: stackoverflow