0

Injecting reference in a div with a view model

asked 2012-05-28 10:46:31 +0800

kjir gravatar image kjir
24

updated 2012-05-28 13:07:15 +0800

Hi,
I have a page with 2 view models:

<?page title="Manage stands" contentType="text/html;charset=UTF-8"?>
<div apply="org.zkoss.bind.BindComposer"
	viewModel="@id('vm') @init('com.mycompany.FirstViewModel')">
<!-- A lot of unimportant stuff -->
    <tabbox>
		<tabs>
			<tab label="Tab1" ></tab>
                        <!-- Other unimportant tabs -->
		</tabs>
		<tabpanels>
			<tabpanel>
			<include src="inc/other.zul" p="@ref(vm.selected)" pid="@ref(vm.selected.id)" ></include>
			</tabpanel>
		</tabpanels>
	</tabbox>
</div>

The include is like this:

<window>
<label id="sid" value="@load(pid)" ></label>
<div apply="org.zkoss.bind.BindComposer"
	viewModel="@id('vms') @init('com.mycompany.SecondViewModel')">
	<listbox model="@id('vars') @load(p.someList)"
		selectedItem="@bind(vms.selected)"
		emptyMessage="No data in list">
                <!-- Template and stuff -->
	</listbox>
	<label id="sid1" value="@load(pid)" ></label>
</div>
</window>

The problem is that once I define the second viewModel, all the external references are inaccessible: I have a value for the first label, but I have no values for the listbox or the second label. Is there a way to do that? I tried with no success to do this:

<div apply="org.zkoss.bind.BindComposer"
	viewModel="@id('vms') @init('com.mycompany.SecondViewModel')" list="@ref(p.someList)">
	<listbox model="@id('vars') @load(list)"
		selectedItem="@bind(vms.selected)"
		emptyMessage="No data in list">

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2012-05-29 10:31:14 +0800

kjir gravatar image kjir
24

No ideas? I wouldn't want to merge the second viewModel in the first one, it would be very ugly and messy...

link publish delete flag offensive edit

answered 2012-05-30 11:10:39 +0800

iantsai gravatar image iantsai
2755 1

Sorry, this is a bug and we are working on it.
please track the issue status here:
http://tracker.zkoss.org/browse/ZK-1165

link publish delete flag offensive edit

answered 2012-05-30 12:53:26 +0800

kjir gravatar image kjir
24

That's too bad! Thank you for filing the bug, in the meantime anyone has a suggestion for a workaround? Or my only option is to rewrite everything to use just one ViewModel?

link publish delete flag offensive edit

answered 2012-05-30 14:46:58 +0800

iantsai gravatar image iantsai
2755 1

updated 2012-05-30 14:50:46 +0800

I'll suggest you make secondViewModel become a member field of FirstViewModel, and provide a getter method for it.
So, your include will be like this:

 
<include src="inc/other.zul" p="@ref(vm.selected)" pid="@ref(vm.selected.id)"  vms="@ref(vm.secondVModel)"></include>

then in your other.zul:

<window>
<label id="sid" value="@load(pid)" ></label>
<div>
	<listbox model="@id('vars') @load(p.someList)"
		selectedItem="@bind(vms.selected)"
		emptyMessage="No data in list">
                <!-- Template and stuff -->
	</listbox>
	<label id="sid1" value="@load(pid)" ></label>
</div>
</window>

I think in most of your cases this should work, and the good part of this design is your VM can communicate to each other in a much direct way.

link publish delete flag offensive edit

answered 2012-05-30 15:13:14 +0800

kjir gravatar image kjir
24

I did something very similar myself, but yours is better! The only problem is that @Commands do not work so I have to add them to the first ViewModel...

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

Follow

RSS

Stats

Asked: 2012-05-28 10:46:31 +0800

Seen: 274 times

Last updated: May 30 '12

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