0

Setter for data in SimpleListModel

asked 2012-01-25 05:04:31 +0800

RichardL gravatar image RichardL
768 4

Hi all,
I've got an auto complete combobox with a custom model that extends SimpleListModel. To get my sublist for the auto complete I override getSubModel(Object obj, int nRows). I am setting the model with an empty list to start and then fetching from the database for each submodel (the data is huge, so this way is more efficient).

I also have a renderer which sets both a label and a value to each combitem. I have an onChange event listener in the combobox where I want to get the value of the comboitem (not the label - I know I could just get that by getting the value of the combobox):

this.addEventListener("onChange", new EventListener() {

            public void onEvent(Event e) throws Exception {
                Executions.sendRedirect("index.zul?bun=" + FindUsersAutoCompleteCombo.this.getSelectedItem().getValue());
            }
        });

The trouble is, the getSubModel method doesn't update the data in SimpleListModel, so when I try to get the value of the comboitem I get this error (remember, I started out with an empty list in the model, and it hasn't been updated):

SEVERE: java.lang.ArrayIndexOutOfBoundsException: 2
	at org.zkoss.zul.SimpleListModel.getElementAt(SimpleListModel.java:92)
	at org.zkoss.zul.Combobox.syncSelectionToModel(Combobox.java:609)

This could be solved simply with a setter for data in SimpleListModel, so the data can be updated in the getSubModel method.

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2012-01-25 07:11:23 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Thanks Richard

link publish delete flag offensive edit

answered 2012-01-25 07:59:51 +0800

RichardL gravatar image RichardL
768 4

Hi terrytornado,
Sorry if I wasn't clear. My point was that there is no setter for data in SimpleListModel and for cases where the data is reset in getSubModel, there should be. I could be wrong and there may be some workaround, but if not I'll make a feature request.

link publish delete flag offensive edit

answered 2012-01-25 10:47:27 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Hi Richard, the zk guys will read this. But a feature request will be saver, you are right :-)

link publish delete flag offensive edit

answered 2012-01-25 19:40:43 +0800

Matze2 gravatar image Matze2
773 7

And have in mind, it's Chinese New Year...

link publish delete flag offensive edit

answered 2012-01-26 02:55:28 +0800

RichardL gravatar image RichardL
768 4

Thanks, Matze2. I made a feature request: http://tracker.zkoss.org/browse/ZK-795. Happy Chinese New Year! :)

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-01-25 05:04:31 +0800

Seen: 576 times

Last updated: Jan 26 '12

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