-
New Feature
-
Resolution: Fixed
-
Normal
-
6.5.2
-
Security Level: Jimmy
-
None
-
None
http://screencast.com/t/oPc4LVgBTsc4
public class MyVM { private Data data = new Data(); public Data getData() { return data; } public void setData(Data data) { this.data = data; } public Validator getValidator() { return new AbstractValidator () { public void validate(ValidationContext ctx) { String val = (String)ctx.getProperty().getValue(); if (val == null || val.trim().length() == 0) { addInvalidMessage(ctx, "please type text"); } Component comp = ctx.getBindContext().getComponent(); if (comp != null) { System.out.println(comp + ": " + ctx.isValid()); ((HtmlBasedComponent)comp).setSclass( ctx.isValid() ? "": "red"); } } }; } @Command public void save() { } public static class Data { private String value1 = "val1"; private String value2 = "val2"; public String getValue1() { return value1; } public void setValue1(String value) { this.value1 = value; } public String getValue2() { return value2; } public void setValue2(String value) { this.value2 = value; } } }
<zk> <style> .red, .red .label-textbox-input { border: 1px solid red; } .label-textbox-macro { border: none; } </style> <window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('foo.MyVM')" validationMessages = "@id('vmsgs')"> <div form="@id('fx') @load(vm.data) @save(vm.data, before='save')"> <vlayout> <textbox id="val1Tb" value="@bind(fx.value1)@validator(vm.validator)" /> <textbox id="val2Tb" value="@bind(fx.value2)@validator(vm.validator)"/> <label value="@load(vmsgs[val1Tb])" /> <label value="@load(vmsgs[val2Tb])" /> <button label="save" onClick="@command('save')"/> </vlayout> </div> </window> </zk>