-
FEATURED COMPONENTS
First time here? Check out the FAQ!
In my application, there is a Listbox whose ListModelList I want to clear. However, each time I do this there is an UiException coming up:
"Removal causes a larger list? oldsz:0, newsz:0" in LiveListboxDataLoader.doLiveListDataChange(LiveListboxDataLoader:121)
After examining the problem, I suspect an error in the ZK framework. This is the code from ListModelList:
public void clear() {
int i2 = list.size() - 1; if (i2 < 0) { return; } _list.clear(); fireEvent(ListDataEvent.INTERVALREMOVED, 0, i2); }
It looks, as if at first, the list from the ListModelList is cleared, and then the ListDataEvent "INTERVALREMOVED" is fired. This leads then to a call of LiveListboxDataLoader.doLiveListDataChange(ListDataEvent event). There, the size of the list from the event source ("newsz") is checked against "oldTotalSize". This parameter is, however, also set in the "fireEvent(...)" method called in "ListModelList.clear()" (implemented in AbstractListModel, line 57):
protected void fireEvent(int type, int index0, int index1) { final ListDataEvent evt = new ListDataEvent(this, type, index0, index1); for (ListDataListener l : _listeners) l.onChange(evt); }
This is the line:
final ListDataEvent evt = new ListDataEvent(this, type, index0, index1);
Here, a new ListDataEvent is created, including a reference to the ListModel ("this").
But as this is done AFTER the list has been cleared, both the old and the new list are of size 0. As a result, the Exception "Removal causes a larger list? oldsz:0, newsz:0" comes up.
As this was quite complicated, here again in short: - When clearing a ListModelList, at first the internal list is cleared. - Then, a new Event is fired, based on the already cleared list - This is then compared to the cleared list. - As both lists are 0, it seems like there is nothing to clear, and the Exception comes up.
Am I doing something wrong here, or is it possible that there is an Error in the ZK Framework? Looking forward to all your answers.
Cheers, EBlues2000
Hi EBlues,
this example works for me using ZK 6.5.3 EE ...
<zk>
<div apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('zk.support.listmodel.ListModelClearTest')">
<button label="clear list" onClick="@command('clear')" />
<button label="fill list" onClick="@command('fill')" />
<listbox model="@load(vm.model)">
<template name="model">
<listitem>
<listcell label="@load(each)"></listcell>
</listitem>
</template>
</listbox>
</div>
</zk>
and viewmodel
package zk.support.listmodel;
import org.zkoss.bind.annotation.Command;
import org.zkoss.zul.ListModelList;
public class ListModelClearTest {
private ListModelList<String> model = new ListModelList<String>(new String[] {"item1", "item2"});
public ListModelList<String> getModel() {
return model;
}
@Command("clear")
public void clear() {
model.clear();
}
@Command("fill")
public void fill() {
model.add("newitem1");
model.add("newitem2");
model.add("newitem3");
}
}
can you provide an example to reproduce together with the zk-version/edition used?
Cheers, Robert
Asked: 2013-07-26 10:10:42 +0800
Seen: 30 times
Last updated: Aug 05 '13
ArrayIndexOuOfBoundsException showing Messagebox
error PWC2788: setAttribute: Non-serializable attribute with name javax.zkoss.zk.ui.Session
no grammar constraints (dtd or xml schema) detected for the document
Getting wierd NullPointerException when using Shiro
Script error when doing stuff in background thread
XPAGES with Customize excel cells