0

command for a item in list

asked 2013-02-22 22:37:06 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-02-22 22:37:06 +0800

Shahbour gravatar image Shahbour
1

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

delete flag offensive retag edit

Comments

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 )edit

So you will want to call child class

sjoshi ( 2013-02-25 05:12:34 +0800 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2013-02-25 08:52:54 +0800

Shahbour gravatar image Shahbour
1

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

link publish delete flag offensive edit
0

answered 2013-02-25 03:21:37 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-02-25 03:22:08 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

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

answered 2013-02-23 11:24:23 +0800

this post is marked as community wiki

This post is a wiki. Anyone with karma >100 is welcome to improve it.

updated 2013-02-23 11:24:23 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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

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

Follow
1 follower

RSS

Stats

Asked: 2013-02-22 22:37:06 +0800

Seen: 53 times

Last updated: Feb 25 '13

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