0

ListBox issue: onSelect fired before binding selected item

asked 2015-07-31 07:33:39 +0800

OlivierULg gravatar image OlivierULg
1

updated 2015-07-31 07:34:32 +0800

Hi,

Beginner in zk, I'm facing an issue I can't solve. In MVVM, I have a ListBox and I'd like to refresh an Include using the selected item of my ListBox as parameter. To achieve this, I bind the selectedItem property of the ListBox with my ViewModel and I add an invalidate of my include on the onSelect property. The issue is that when I'm selecting an Item, the include is refreshed but with the previously selected Item. I assume that the onSelect event is fired before the binding of the selectedItem property.

Any clue to solve that problem? Thank you very much.

PS: If the invalidate is fired from the onClick event of the listcell, it works fine, but we lose the ability to select an item with the keyboard.

Here is the zul:

<hbox apply="org.zkoss.bind.BindComposer"
viewModel="@id('pa') @init('ulis.zk.wizard.webapp.viewmodel.ParamsViewModel')" hflex="1">
<vbox hflex="1">
    <button label="+" onClick="@command('addParam')" />
    <listbox model="@load(pa.params)" selectedItem="@bind(pa.selectedParam)" onSelect="paramsInclude.invalidate()">
        <template name="model" var="item">
            <listitem draggable="true" droppable="true">
                <listcell>
                    <label value="@load(item.clazz.simpleName)"/>
                </listcell>
            </listitem>
        </template>
    </listbox>
</vbox>
<include id="paramsInclude" hflex="4" type="@ref(pa.selectedParam.type)" bean="@ref(pa.selectedParam.clazz)" src="@load('/beanView.zul')"/></hbox>
delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2015-07-31 18:50:21 +0800

Darksu gravatar image Darksu
1991 1 4

Hello OlivierULg,

I would recommend that you should use a slightly different approach with Java:

  • Remove the onSelect
  • Use the selected item parameter when the event is triggered
  • Get the selected values from the selected item

http://books.zkoss.org/wiki/ZKDeveloper'sReference/MVVM/DataBinding/CollectionandSelection#BindingtoSelectedItem

  • Pass again the values to the include component

http://books.zkoss.org/wiki/ZKDeveloper%27sReference/UIComposing/ZUML/LoadZUMLinJava

  • Use NotifyChange where necessary

http://books.zkoss.org/zk-mvvm-book/8.0/viewmodel/notification.html

Best Regards,

Darksu

link publish delete flag offensive edit
0

answered 2015-08-03 08:16:50 +0800

OlivierULg gravatar image OlivierULg
1

Hello Darksu,

Thank you for your answer. I don't get what you mean by "Pass again the values to the include component". If I correctly get it, at this step, I should be in the setter of the selected item. There, I don't have any reference to the included component nor the parent.

By yhe way, the source of the include is not changing, only the parameters. Souldn't I invalidate it someway if I want a refresh?

Thank you for your help,

OlivierULg.

link publish delete flag offensive edit
0

answered 2015-08-03 09:22:20 +0800

OlivierULg gravatar image OlivierULg
1

Hello Darksu,

I finally manage to implement your solution. I have an Init to pass the parent component and, in the setter of the selected item, I remove the old include and create a new one with the new parameters. It works fine. It's not pure MVVM because I manipulate components in java, but the result is here.

Kind regards,

OlivierULg.

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: 2015-07-31 07:33:39 +0800

Seen: 76 times

Last updated: Aug 03 '15

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