0

ListModelList.clear() - Error in ZK Framework?

asked 2013-07-26 10:10:42 +0800

eblues2000 gravatar image eblues2000
0

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

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-08-05 09:27:37 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2013-08-05 09:28:53 +0800

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

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-07-26 10:10:42 +0800

Seen: 30 times

Last updated: Aug 05 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More