Reputation: 10652
Let's assume a simple zul in zk 8...
<div width="100%" height="100%" viewModel="@id('vm') @init('com.example.MyVM')">
<div visible="@load(vm.child.isElementVisible)"/>
<div visible="@load(not vm.child.isElementVisible)"/>
<button onClick="@command('doSomething')"/>
</div>
Now I've got a simple comand in the VM...
@Command
@NotifyChanges({"child.elementVisible", "someotherproperty"})
public void doSomething() {
this.child.setElementVisible( !this.child.isElementVisible() );
}
Unfortunately, this doesn't work at all. The visibilty doesn't change. As the initial value of the visibility works fine, it seems that only the change notification doesn't seem to work.
But if I add a delegate method to the vm itself...
public boolean isElementVisible() {
return this.child.isElementVisible();
}
...and use that in my zul...
<div visible="@load(vm.isElementVisible)"/>
<div visible="@load(not vm.isElementVisible)"/>
...it works perfectly fine. Has anyone an idea why the notification here fails?
Upvotes: 1
Views: 614
Reputation: 370
Try this source http://zkframeworkhint.blogspot.it/2014/05/how-to-notify-single-item-or-record-or.html by the great Subodh Joshi.
The concept is use in view:
<textbox value="@bind(mymodel.b)" onChange="@command('changeAnotherTextBox',data = mymodel)"/>
and in viewmodel:
@Command
public void changeTextBox(@BindingParam("data") Data data) {
data.setB("Hariom=>" + data.getA());
BindUtils.postNotifyChange(null, null, data, "b");
}
Upvotes: 1
Reputation: 10652
Ah, it seems that @NotifyChange does not support child properties like...
@NotifyChanges({"child.elementVisible", "someotherproperty"})
Instead we have to use something like this...
BindUtils.postNotifyChange(null, null, child, "elementVisible");
...which does seem to work. And we have to hope for the other thing as a new feature ;-)
Upvotes: 2