Page as ZUL component, multiple instances of the same VM on one page

asked 2014-05-29 23:37:07 +0800

tomr gravatar image tomr
1 1

updated 2014-05-29 23:43:48 +0800

I am investigating multi-tab solution for single-page application (something like zksample2). The requirements are that each new document (e.g. invoice) should be opened in new page. E.g. there can be "New invoice" command on the toolbar and when user clicks it two times, then 2 new tabs are opened and 2 new invoices are created (e.g. with Id 5 and 6).

The question is - how to implement such requirements.

My idea is to create new zul component that can be used for displaying invoice. That is clear. It is also clear how to create new instance of InvoiceZUL at runtime - the code can be similar to tab_plus demo code.

The problem is about reference to ModelView. My understanding is that 2 instances of ModelView should be created and assigned to some array of available ModelView's. The question is - how can I indicate that the instace 1 of InvoiceZUL should used instance 1 of InvoiceMV and instance 2 of InvoiceZUL should use instance 2 of InvoiceMV.

Static solution is to write code: viewModel="@id('vm') @init('org.zkoss.essentials.chapter6.mvvm.TodoListViewModel')"

Maybe such references can be created dynamically in the main ZUL file? E.g. maybe I can create dynamically reference vmi and indicate that invoiceZULi should used vm_i?

Does ZK supports such use cases?

And one more question. Event names are usually hard-coded in the class of ViewModel. All is clear if only one ViewModel exists. But what happens if one ZUL pages uses multiple instances of the same ViewModel class. E.g. to distinct Invoices are being edited and use clicks on Invoice Id 5 to save data. SaveInvoice event is raised and how can ZK binder determine that instance InvoiceVM[5] should handle this event and not other instances?

Thanks for any suggestions in advance

delete flag offensive retag edit
Be the first one to answer this question!
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

1 follower



Asked: 2014-05-29 23:37:07 +0800

Seen: 31 times

Last updated: May 29 '14

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