The way to reproduce :
- create a Listbox (with ROD) with a specified height
- set a ListModel (listbox.setModel(Listmodel model)) with a large dataset (> 500 Listitems) to the Listbox
- Scroll down to the Listbox
- Set a new Listmodel (setModel) with few Listitem (5 Listitems)
- The scroll bar stay a the same position and the Listitems are not correct
Reproducible on 5.0.7.1 EE and 5.0.8-FL EE version on any browser
test.zul code
<zk xmlns:w="http://www.zkoss.org/2005/zk/client">
<window id="win" border="none" apply="test.ListboxControl">
<custom-attributes org.zkoss.zul.listbox.rod="true"/>
<listbox checkmark="true" multiple="true" id="testListbox" height="400px" width="800px">
<listhead sizable="true">
<listheader label="Test"/>
</listhead>
</listbox>
<button id="btnNewModel" label="Run Bug (make a scroll to the middle first)"/>
</window>
</zk>
test/ListboxControl.java (test.ListboxControl)
package test;
import java.util.ArrayList;
import java.util.List;
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;
public class ListboxControl extends GenericForwardComposer {
private Listbox testListbox;
/**
*
*/
private static final long serialVersionUID = -8768290877229863939L;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
testListbox.setItemRenderer(new ListitemRenderer() {
@Override
public void render(Listitem arg0, Object arg1) throws Exception {
arg0.setValue(arg1);
DummyItem di = (DummyItem) arg1;
Listcell lc = new Listcell();
lc.setLabel(di.getTest());
lc.setParent(arg0);
}
});
List<DummyItem> ditems = generateDummyItems("First items", 500);
ListModelList lstModelList = new ListModelList(ditems);
testListbox.setModel(lstModelList);
}
public void onClick$btnNewModel() {
List<DummyItem> ditems = generateDummyItems("Second items", 5);
ListModelList lstModelList = new ListModelList(ditems);
testListbox.setModel(lstModelList);
}
public static List<DummyItem> generateDummyItems(String prefix, int size) {
List<DummyItem> newList = new ArrayList<DummyItem>();
for (int i = 0; i < size; i++) {
newList.add(new DummyItem(prefix + i));
}
return newList;
}
public static class DummyItem {
protected String test;
public DummyItem() {
}
public DummyItem(String test) {
setTest(test);
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
}
as mentioned on http://www.zkoss.org/forum/listComment/16780
This artifact has been marked as a duplicate of artifact 3352909 with reason:
No explanation provided.
reopen this bug, this case is not real duplicated with another.
Bug fixed since 2011/07/14