Skip to content

Instantly share code, notes, and snippets.

@faisal-w
Created September 20, 2012 09:16
Show Gist options
  • Save faisal-w/3754853 to your computer and use it in GitHub Desktop.
Save faisal-w/3754853 to your computer and use it in GitHub Desktop.
ZK Listbox Controller Example 1
package controllers;
import java.util.ArrayList;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import domain.Person;
public class ListboxController extends GenericForwardComposer{
/**
*
*/
private static final long serialVersionUID = 7878488384821093970L;
private Listbox shoppingCartListbox;
ArrayList<Person> personData;
@Override
public void doAfterCompose(Component comp) throws Exception {
// TODO Auto-generated method stub
super.doAfterCompose(comp);
fillData();
shoppingCartListbox.setItemRenderer(new ListitemRenderer<Person>() {
@Override
public void render(Listitem item, Person data, int index)
throws Exception {
// TODO Auto-generated method stub
new Listcell(data.getId()+"").setParent(item);
new Listcell(data.getFirstName()).setParent(item);
new Listcell(data.getLastName()).setParent(item);
new Listcell(data.getMoney()+"").setParent(item);
item.setValue(data);
}
});
}
private void fillData(){
Person data1 = new Person(1,"Sudi","Anto",55.0);
Person data2 = new Person(2,"Erwin","Ndombos",512.4);
Person data3 = new Person(3,"Inung","Affandi",24.1);
personData = new ArrayList<Person>();
personData.add(data1);
personData.add(data2);
personData.add(data3);
ListModelList lml = new ListModelList(personData,true);
shoppingCartListbox.setModel(lml);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment