0

ListModelList notifyChange

asked 2021-09-29 16:06:03 +0800

aUser gravatar image aUser
133 4

Hello,

suppose I have this .zul file:

<zk>
    ...
    <grid model="@load(vm.names)" visible="@load(not empty vm.names)">
        <columns>
            <column label="Name" align="center" />
        </columns>
        <template name="model" var="name">
            <row>
                <label value="@load(name)" />
            </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();
    names.addAll(getNames());
}

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 flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-09-30 10:55:52 +0800

cor3000 gravatar image cor3000
6168 2 7
ZK Team

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.

link publish delete flag offensive edit

Comments

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

aUser ( 2021-10-01 16:06:13 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2021-09-29 16:06:03 +0800

Seen: 5 times

Last updated: Sep 30

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More