# ListModelList notifyChange

aUser
133 4

Hello,

suppose I have this .zul file:

<zk>
...
<columns>
<column label="Name" align="center" />
</columns>
<template name="model" var="name">
<row>
</row>
</template>
</grid>

<button label="Update names" onClick="@command('updateNames')" />
...
</zk>


In the VM, i have something like this:

private List<String> names = new ListModelList<String>();
...
@Command
public void updateNames() {
names.clear();
}

public List<String> getNames() {
return names;
}
...


I wanted the grid in the .zul page to be visibile only when the model was not empty but this doesn't work. In this scenario, the grid is never visible. To make it visible/invisible based on the data of the model, I have to post a NotifyChange (either by BindUtils.postNotifyChange(...) or @NotifyChange annotation).

It's kinda annoying because I want to use the ListModelList implementation to not send notifications. Of course, if I remove the visible property of the grid, for the sake of clarity like this:

<grid model="@load(vm.names)">


the grid is updated each time the number of rows changes.

Can I do something to not send a NotifyChange in order to make the grid visible only when the model contains rows?

Thank you

delete retag edit

Sort by » oldest newest most voted

cor3000
6168 2 7

Not really, since the expression vm.names doesn't change when the contents change the load binding will not evaluate automatically.

However you can make the load binding evaluate conditionally based on command e.g. your updateNames-command.

visible="@load(not empty vm.names, after='updateNames')"


Maybe that's good enough for your scenario.

Thank you, that is enough for what I have to do

( 2021-10-01 16:06:13 +0800 )edit
[hide preview]