# ListBox issue: onSelect fired before binding selected item

OlivierULg
1

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">
<template name="model" var="item">
<listitem draggable="true" droppable="true">
<listcell>
</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 retag edit

Sort by » oldest newest most voted

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
• Pass again the values to the include component
• Use NotifyChange where necessary

Best Regards,

Darksu

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?

OlivierULg.

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.

[hide preview]