-
FEATURED COMPONENTS
First time here? Check out the FAQ!
asked 2013-02-22 22:37:06 +0800
This post is a wiki. Anyone with karma >100 is welcome to improve it.
Hello
i am following MVVM with tabbox children to create different tabs views for different classes, every thing is working perfect except for the command binding from child classes they are always looking at main viewmodel (for label/textbox binding it is working perfect).
Here you can see my main zul page
<tabbox id="maintb" height="100%" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('xxxxxx.MainViewModel')">
<tabs id="tabs" children="@load(vm.tabList)"
onSelect="@command('selecttab',item=each)" onClose="@command('closetab',item=each)">
<template name="children">
<tab closable="true" label="@load(each.header)" />
</template>
</tabs>
<tabpanels children="@load(vm.tabList) @template(each.type)">
<template name="children" var="tab">
<tabpanel>
<label value="children" />
</tabpanel>
</template>
<template name="first" var="tab">
<tabpanel>
<include src="dashboard.zul"></include>
</tabpanel>
</template>
<template name="CDRServerStatus" var="tab" >
<tabpanel>
<include src="cdrserverstatus.zul"></include>
</tabpanel>
</template>
</tabpanels>
</tabbox>
i got differnet templates for different types , now for third template below is the code
<vlayout>
<button label="Get Status" onClick="@command('getstatus')"></button>
<textbox value="@bind(tab.test)"></textbox>
<listbox vflex="true" hflex="1" model="@bind(tab.cDRServerStatusList)">
<listhead>
<listheader label="Site" width="80px" align="center" />
<listheader label="Count" align="center" />
</listhead>
<template name="model" var="cDRStatusVM">
<listitem>
<listcell label="@load(cDRStatusVM.siteName)" />
<listcell label="@load(cDRStatusVM.CDRsCount)" />
</listitem>
</template>
</listbox> </vlayout>
Listbox is showing the items correctly but the button when trying to fire the command it is searching for a command on the mainviewmodel while i want it to search for this tabviewmodel "tab.command" .
I know i can do this using global command but i might want to add multiple tabs of same time so it is not an option.
Is there any way to tell the @command to search in sub context same as i am binding my label and list to tab.property .
Best Regards Shahbour
answered 2013-02-23 11:24:23 +0800
This post is a wiki. Anyone with karma >100 is welcome to improve it.
I think you can do it ..
@Command
public void doSomething(@ContextParam(ContextType.VIEW) Component view) {
Binder bind = (Binder) view.getParent().getAttribute("binder");
if (bind == null)
return;
bind.postCommand("callMe", params);//callMe is Parent Class Method
}
See if it will hep you
answered 2013-02-25 03:21:37 +0800
This post is a wiki. Anyone with karma >100 is welcome to improve it.
what is the tabviewmodel? is it the tab
var?
the you could use nested viewmodel by
<vlayout apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init(tab)">
<button label="Get Status" onClick="@command('getstatus')"></button>
<textbox value="@bind(vm.test)"></textbox>
<listbox vflex="true" hflex="1"
model="@bind(vm.cDRServerStatusList)">
<listhead>
<listheader label="Site" width="80px" align="center" />
<listheader label="Count" align="center" />
</listhead>
<template name="model" var="cDRStatusVM">
<listitem>
<listcell label="@load(cDRStatusVM.siteName)" />
<listcell label="@load(cDRStatusVM.CDRsCount)" />
</listitem>
</template>
</listbox>
</vlayout>
Hello
Yes it is nested viewmodel but not a tab .
I tried putting @init(tab) but it didn't work the way it worked is as below
<vlayout apply="org.zkoss.bind.BindComposer" viewModel="@id('childObj') @init({tab})">
Best Regards
Shahbour
Asked: 2013-02-22 22:37:06 +0800
Seen: 53 times
Last updated: Feb 25 '13
Using databinding in menupopup
ZK Clustering, Session Replication Question [closed]
Problem binding values to a composite component
How can i load a constant in .zul
set selectedItem of list in viewmodel - cleaner way? [closed]
search button using validation
[Ugent please] connect Web service .net view in grid group ZK
Hello
Thanks for the reply but my problem is not calling the parent class, completely the opposite , the button inside each tab is complaining that it didn't find any command in the parent calls.
I want to call the function found in the tab context. what is happening with me is that when i click
Shahbour ( 2013-02-23 16:18:21 +0800 )editSo you will want to call child class
sjoshi ( 2013-02-25 05:12:34 +0800 )edit