First time here? Check out the FAQ!
I have a zul and VeiwModel to him whit button
<window title="title" border="normal" closable="true"
viewModel="@id('vm') @init('foo.myVM')"
apply="org.zkoss.bind.BindComposer" onClose="@command('close')"
id="foo">
<button image="resources/images/delete.png"
onClick="@command('openDeleteWnd')" />
</window>
Button open new window .This code is in myVM
private Object objectToEdit;
@Command
public void openDeleteVehicleWnd(){
Window win = null;
win = (Window) Executions.createComponents("edit.zul", null,null);
win.setWidth("400px");
win.setHeight("400px");
win.doModal();
}
and i whant new window to use same ViewModel because the changes I'll make there reflect on the "objectToEdit" that is in the current viewModel
this is button zul:
<window title="edit" border="normal" closable="true"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('foo.myVM')"
id="editWnd">
<vbox>
<label value="Text" />
<textbox rows="10" cols="50" value="@bind(vm.objectToEdit.text)"/>
<hbox width="100%" pack="center" height="100%">
<button label="Save" />
</hbox>
</vbox>
</window>
I try to use viewModel="@id('vm') @init('foo.myVM')" and value="@bind(vm.objectToEdit.text) but throws a mistake because of viewModel="@id('vm') @init('foo.myVM')". How can I use two windows with a one ViewModel. Or how to solve the problem without creating a new one ViewModel.
Hi Radoslav,
your question goes in a very similar direction as a recent question passing-parameters-from-a-viewmodel-to-another-one.
The same technique can be used in your case, except you can just use @Command
instead of @GlobalCommand
. If you don't like the <include>
component and rather keep your approach using createComponents
that's also fine.
You can simply pass the objectToEdit
as a parameter:
win = (Window) Executions.createComponents("edit.zul", null, Collections.singletonMap("data", objectToEdit));
You can't use the same view model in 2 places, but you can use the objectToEdit in 2 separate viewModels (e.g. PersonListVM and PersonEditVM). The PersonListVM passes the objectToEdit to the PersonEditVM to perform the updates.
If that doesn't help please let me know.
Robert
Asked: 2018-03-15 00:11:03 +0800
Seen: 28 times
Last updated: Mar 15 '18