First time here? Check out the FAQ!
Hello,
I'm trying to use ListModelList
in order to avoid NotifyChange
.
In my .zul page I have something like this:
<grid model="@load(vm.list) @template('row')">
<rows>
<template name="row">
<row>
<checkbox checked="@load(each.isModified)" />
</row>
</template>
</rows>
</grid>
And in my bean object i have a utility method that is like this:
public Boolean getIsModified() {
return "Y".equalsIgnoreCase(this.aString); // aString is a bean property that has getter and setter
}
Being an utility method, isModified
is not a bean property, it's just a simple method.
Whenever i change the aString
bean property however, the ListModelList
doesn't call this utility method to update the state of the checkbox. Is there a way (except using NotifyChange
) to make the ListModelList
call this utility method when the property aString
is changed?
Also, if i have to reload the data of a ListModelList
, why can't i use this?
ListModelList<Object> list = new ListModelList<Object>(); // initialization
....
@Command
public void updateCollection() {
list = new ListModelList<Object>(collection);
}
Currently i'm using this instead, which is kinda ugly in my opinion..
ListModelList<Object> list = new ListModelList<Object>(); // initialization
....
@Command
public void updateCollection() {
list.clear();
list.addAll(collection);
}
Thank you
EDIT:
I solved the first problem using list.notifyChange(item);
from java code when i update an item.
good you found the notifyChange(item)
method, that's the dedicated way to rerender a specific row.
A more granular way to reload just the checked property would have been:
BindUtils.postNotifyChange(item, "modified")
even though it's not an instance variable on your bean, it's still a readonly bean-property just by having a getXXX or isXXX method available.
If you read the docs carefully they only mention methods defining a bean property not the actual instance variable.
This is a very useful feature for computed properties for something like fullName
or totalPrice
public String getFullname() {
return this.lastName + ", " + this.firstName;
}
Your second problem is not a problem... clearing a collection and adding items back into it is not ugly. It's perfectly reusing the existing listModelList, in the same way as if you'd just add/remove individual items - can't get simpler than that. And everyone reading your code will instantly know what's your intention.
If you really want to build a new ListModelList you have to notify the viewmodel about the updated property to trigger the load-binding.
@Command
@NotifyChange("list")
public void updateCollection() {
list = new ListModelList<Object>(collection);
}
or via java
@Command
public void updateCollection() {
list = new ListModelList<Object>(collection);
BindUtils.postNotifyChange(this, "list");
}
BindUtils.postNotifyChange(item, "modified");
is definitely better in this case i guess.. In fact it makes no sense to update the whole row if only one element is changed.
Thanks for the hint about the collection. Yeah, i don't really need to create a new ListModelList, i will simply stick to clear and adding the new collection then
Asked: 2021-01-11 22:54:16 +0800
Seen: 6 times
Last updated: Jan 13
zkspringmvc jar licence is GPL ?
Build web application without any zul files
Custom component that extends Textbox does not fire onChange event
java.lang.NullPointerException to update to zk 8.0.1
"Spring Session" + ZK + "Spring core" @Listen method refresh the screen
zk8 client side binding to a viewmodel command seems not to work