How can I pass on the onCheck event of a Checkbox to its parent in zk?

Viewed 796

I have a vbox with some checkboxes in it, like so:

<vbox id="myVbox" apply="org.zkoss.bind.BindComposer"
   viewModel="@id('vm') @init('my.checkbox.group.CheckboxGroupViewModel', outerVM=wvm, component=self)">
   <checkbox id="1"/>
   <checkbox id="2"/>
   <checkbox id="3"/>
</vbox>

Is there a way to make the vbox react to any of its children's onCheck event?

Edit:

The vbox is part of a window that has its on viewmodel. In it, there is the following code to add the radios dynamically:

if (childName.equals("org.zkoss.zul.Checkbox")) {
                    child.addEventListener("onClick", new EventListener<Event>() {
                        @Override
                        public void onEvent(Event event) throws Exception {
                            Events.sendEvent(new Event("onSelectionChange",parent));                        
                        }                       
                    });
                }

The parent variable represents the vbox. The viewmodel of the vbox contains an onSelectionChange method. But it seems to never get called.

2 Answers

You might try this:

<vbox onSelectionChange="@command('METHODNAME_TO_IMPLEMENT_EVENT')"/>

How do you want it to react? You could do something like:

<vbox id="myVbox">
    <checkbox id="1" onCheck="myVbox.visible=false"/>
    <checkbox id="2"/>
    <checkbox id="3"/>
</vbox>
Related