Revision history [back]

click to hide/show revision 1
initial version

answered 2012-08-10 17:33:50 +0800

stream gravatar image stream

Hi Dennis, event.value doesn't work. But it works if I get event value through ContextParam. I have prepared test with all possible ways, that I could come up, to pass value to ViewModel by using ZK 6 binding.

zul: <window border="none" apply="org.zkoss.bind.BindComposer" viewmodel="@id('vm') @init('se.spn.test.TextboxVM')"> textbox: <textbox id="t1" value="@load(vm.selection) @save(vm.selection, before='doCommand')" onchanging="@command('doCommand', self_value=self.value, event_value=event.value)" width="100px"></textbox> </window>

view model: public class TextboxVM { private String selection; @AfterCompose public void doAfterCompose(@ContextParam(ContextType.VIEW) Component view) throws Exception { Selectors.wireEventListeners(view, this); } public String getSelection() { return selection; } public void setSelection(String selection) { this.selection = selection; }

@Command
public void doCommand(@BindingParam("self_value") String self_value, @BindingParam("self_value") String event_value,
        @ContextParam(ContextType.TRIGGER_EVENT) InputEvent event) {
    System.out.println("doCommand: selection: " + selection + "       self_value: " + self_value + "          event_value: "
            + event_value + "          event_value2: " + event.getValue());
}

@Listen("onChanging=#t1")
public void onChanging(InputEvent event) {
    System.out.println("onChanging=#t1: event_value3: " + event.getValue());
}

}

log: doCommand: selection: selfvalue: eventvalue: eventvalue2: 1 onChanging=#t1: eventvalue3: 1 doCommand: selection: selfvalue: eventvalue: eventvalue2: 2 onChanging=#t1: eventvalue3: 2 doCommand: selection: selfvalue: eventvalue: eventvalue2: 23 onChanging=#t1: eventvalue3: 23 doCommand: selection: selfvalue: eventvalue: eventvalue2: 234 onChanging=#t1: eventvalue3: 234 doCommand: selection: selfvalue: eventvalue: eventvalue2: 2345 onChanging=#t1: eventvalue3: 2345 doCommand: selection: 2345 selfvalue: 2345 eventvalue: 2345 eventvalue2: 2345 onChanging=#t1: eventvalue3: 2345

As you can see 'save before doCommand' saved empty string to selection after I entered '1'. Then there is no updated data in selection variable and values that are passed by using self.value and event.value. But there is the information about update in @ContextParam variable and in listener @Listen("onChanging=#t1").

There is also problem with double invocation of doCommand and onChanging methods in VM when I use debug mode: log: 1st invocation: doCommand: selection: selfvalue: eventvalue: eventvalue2: 1 onChanging=#t1: eventvalue3: 1 doCommand: selection: 1 selfvalue: 1 eventvalue: 1 eventvalue2: 1 onChanging=#t1: eventvalue3: 1 2nd invocation: doCommand: selection: 1 selfvalue: 1 eventvalue: 1 eventvalue2: 2 onChanging=#t1: eventvalue3: 2 doCommand: selection: 2 selfvalue: 2 eventvalue: 2 eventvalue2: 2 onChanging=#t1: eventvalue3: 2

Looks like it is done twice because after first time the value wasn't change properly and then textbox lost focus that allowed to see changes.

For me it looks like a bug

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