Reputation: 11
I have a .zul
file index.zul
. It contain another .zul
file Prueba1.zul
. I am using zk7.
<window border="normal" title="Test Send Argument" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('com.test.ControladorPadre')">
<include type="@load(vm.mapType)" src="Prueba1.zul"/>
....
</window>
</zk>
and
<zk>
<window border="normal" title="Controlador 1" apply="org.zkoss.bind.BindComposer" zclass="z-window-popup"
viewModel="@id('vm') @init('com.test.Controlador1')" >
<button onClick="@command('doSort')" type="button" label="BT1" />
</window>
</zk>
They apply different view-models. I want to sent arguments back from Prueba1.zul
to process to display in index.zul
and process in class ControladorPadre
.
I have tried and searched without success. I currently only know that one way is to use BindUtils.postGlobalCommand
. I am not sure if this is a good way to process or whether there exist another way to resolve my problem.
Upvotes: 1
Views: 963
Reputation: 4277
There is a some solutions
First one is passing your first viewmodel to the second viewmodel.
Documentation of @init says :
viewModel="@id('vm') @init('org.zkoss.reference.developer.mvvm.databinding.InitVM', arg1='myValue')"
so in your case :
viewModel="@id('vm2') @init('com.test.Controlador1', arg1=vm)"
If you look good, I changed the id
of the second vm because you don't want to confuse your zul with the vm.
In Prueba1.zul
the vm is also active and you can load (even save) data there.
Second one : save in vm and vm1.
<textbox value="@load(vm.someText) @save(vm.someText) @save(vm1.someText)"/>
Of course, sometimes you need to pass it after a command and this option would just not work then.
The Global-Command could do the trick,is in mine eyes the best solution, but don't forget all active viewmodels will be checked if that command exist, so make sure you make unique global-commands or you have some unwanted behaviour.
Upvotes: 1