Second zul to View Model

asked 2018-03-15 00:11:03 +0800

Radoslav86 gravatar image Radoslav86
13 3

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')"
      <button image="resources/images/delete.png"                                               
      onClick="@command('openDeleteWnd')" />

Button open new window .This code is in myVM

private Object objectToEdit;
public void openDeleteVehicleWnd(){
    Window win = null;
    win = (Window) Executions.createComponents("edit.zul", null,null);


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"
viewModel="@id('vm') @init('foo.myVM')"

    <label value="Text" />

    <textbox rows="10" cols="50" value="@bind(vm.objectToEdit.text)"/>
    <hbox width="100%" pack="center" height="100%">
        <button label="Save" />


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.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-03-15 12:08:57 +0800

cor3000 gravatar image cor3000
5673 2 7
ZK Team

updated 2018-03-15 12:10:01 +0800

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.


link publish delete flag offensive 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




Asked: 2018-03-15 00:11:03 +0800

Seen: 28 times

Last updated: Mar 15 '18

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