-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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>
Hello OlivierULg,
I would recommend that you should use a slightly different approach with Java:
http://books.zkoss.org/wiki/ZKDeveloper'sReference/MVVM/DataBinding/CollectionandSelection#BindingtoSelectedItem
http://books.zkoss.org/wiki/ZKDeveloper%27sReference/UIComposing/ZUML/LoadZUMLinJava
http://books.zkoss.org/zk-mvvm-book/8.0/viewmodel/notification.html
Best Regards,
Darksu
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.
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.
Asked: 2015-07-31 07:33:39 +0800
Seen: 76 times
Last updated: Aug 03 '15
Binding my button to Upload image MVC
onClick and OnDoubleClick in a single Component
Multiple Controller instances issue
Zk create custom event for COmbo box?
VisibilityChangeEvent Grave NullPointer Exception
Listbox doesn't scroll down on SHIFT+ DOWN key
java.lang.ClassNotFoundException: org.zkoss.zk.ui.http.HttpSessionListener