-
Bug
-
Resolution: Fixed
-
Normal
-
7.0.4
-
Security Level: Jimmy
-
None
The selectedItem with form binding didn't work as expected.
Reproducible steps:
1. Select any item from the drop-down list.
2. Click "Save" button.
3. Should not see "null" in the console.
Repeat step1 and step2 several times, the value is the same with the item you selected (correct) and sometimes the value is null (wrong).
ZUL page
<div apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('org.zkoss.support.imperatives.FormBeanValidatorVM')" validationMessages="@id('vmsgs')" form="@id('fx') @load(vm.bean) @save(vm.bean, before='save') @validator(vm.beanValidator, prefix='p_')"> <combobox id="cbx" model="@load(vm.letters)" selectedItem="@bind(fx.letter)" errorMessage="@load(vmsgs['p_letter'])" onChange="@command('onChangeLetter')"> <template name="model"> <comboitem label="${each}" /> </template> </combobox> <button onClick="@command('save')">Save</button> </div>
ViewModel Class
public class FormBeanValidatorVM { ListModelList<String> letters = new ListModelList<String>(); Bean bean = new Bean(); Validator validator; @Init public void init() { letters.addAll(Arrays.asList(new String[] { "a", "b", "c", "d", "e", "f", "g" })); } @Command public void onChangeLetter() { letters.add("h"); } @Command public void save() { } public ListModelList<String> getLetters() { return letters; } public Bean getBean() { return bean; } public Validator getBeanValidator() { if (validator == null) { //validator = new CascadingFormBeanValidatorService(); validator = new Validator() { public void validate(ValidationContext ctx) { String value = (String) ctx.getProperties("letter")[0].getValue(); System.out.println("Validate value: " + value); } }; } return validator; } public class Bean { @NotBlank private String letter; public String getLetter() { return letter; } public void setLetter(String letter) { this.letter = letter; } } }