-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have upgraded my zk project from zk 7.0.2 to 8.5.0 and I have faced a problem while using
"*" in @NotifyChange. Folliwing is scenario I am facing problem:
I am using combobox and bind a property with selectedItem="@bind(vm.selectedFilter)" and calling a command onChange="@command('filterItems')" and above filterItems command I am using @NotifyChange("*").
<combobox selectedItem="@bind(vm.selectedFilter)"
value="Show All Items" model="@load(vm.itemCategoriesForSearch)"
onChange="@command('filterItems')">
<template name="model">
<comboitem label="${each.name}" />
</template>
</combobox>
and VM code is as follows:
@NotifyChange("*")
@Command
public void filterMenuItems() {
// code to filter items
}
It is creating problem when I selected an item from combobox and it first call setter for selectedFilter() and then command "filterItems" is executed but because of using "*" wildcard in @NotifyChange it is triggering the same event second time but the filters are cleared this time so the output is not as expected.
If anybody face the same problem, or suggestions are welcome.
Thanks for the example!
the event order of the onChange and onSelect event changed somewhere between ZK 7/8/8.5 (I don't recall exactly when)
Combobox unfortunately holds redundant state about selection and text value. If you use either consisitently the problem will go away.
e.g use selectedItem
with onSelect
<combobox autodrop="true" readonly="true"
buttonVisible="true" mold="rounded"
selectedItem="@bind(vm.selectedFilter)"
placeholder="Show All Menu Items"
model="@load(vm.itemCategoriesForSearch)"
onSelect="@command('filterItems')">
or use (text)value
with onChange
<combobox autodrop="true" readonly="true"
buttonVisible="true" mold="rounded"
value="@bind(vm.selectedFilter)"
placeholder="Show All Menu Items"
model="@load(vm.itemCategoriesForSearch)"
onChange="@command('filterItems')">
Both cases worked for me.
However when using @NotifyChange("*")
you are losing some built in functionalities that make this hassle avoidable in the first place.
I took the freedom to remove the unnecessary code in your example (just for your reference): http://zkfiddle.org/sample/4m1jds/31-Issue-while-using-NotifyChange-in-zk-8-5-0
Asked: 2018-11-16 18:59:47 +0800
Seen: 6 times
Last updated: Nov 20 '18
Can't cause update of component visiblity in Window based on changed boolean property
Why does the order of NotifyChange may alter the result of the objects?
MVVM Notifychange works only along with @Command ?
Upload csv files with Zk framework
MVVM Notifychange for bean property not working ?
Create notification icon with zk 7 CE
@NotifyChange not refresh textbox
based on your description it's hard to imagine what's going wrong, can you provide a runnable example on http://zkfiddle.org this will help to illustrate your problem and give us a chance to look at it directly
cor3000 ( 2018-11-19 11:16:13 +0800 )editI have posted an example on zk fiddle, here is the link with example: http://zkfiddle.org/sample/4m1jds/29-Issue-while-using-NotifyChange-in-zk-8-5-0 If I use specific property to notify change like: "@NotifyChange("filteredItems")" on my command then it is filtering correctly. Please have a look.
ShilpaSareen ( 2018-11-19 20:22:03 +0800 )editI have used @NotifyChange("*") at many places in my project, it is incorrectly calling the setter of selectedFilter twice. and the filters are null in second call. It is a big problem for us.
ShilpaSareen ( 2018-11-19 20:41:59 +0800 )edit