-
FEATURED COMPONENTS
First time here? Check out the FAQ!
In the essence of ZK 6 I propose an addiction to the way validations are executed.
Like in the ZUL @command that is attached to a method annotated with @Command, why not do the same with @validator ?
I am detecting a pattern on zul annotations that can be extended and generalized to all.
1. Bind to a viewModel Object invoking get/set => @annotation(vm.object)
Used in @load @save @bind
2. Bind to a method call in the viewModel => @annotation('method_name', ...parameters)
Used in @command @converter
@validator will accept annotated java methods with signature => boolean method_name(...)
Example:
<textbox value="@bind(vm.name) @validator('validateName')"></textbox>
is attached to the java method:
@Validator public String validateName(String name) { if(name == null || name.isEmpty()) return "Name required!" return null; }
or if you don't like the return null:
@Validator public Validation validateName(String name) { if(name == null || name.isEmpty()) return new Validation(Validation.Status.FAIL, "Name required!"); return return new Validation(Validation.Status.OK); }
Hi shumy,
You can refer to http://books.zkoss.org/wiki/Small_Talks/2012/February/MVVM_in_ZK6:_Form_Binding
Asked: 2012-02-10 16:24:11 +0800
Seen: 471 times
Last updated: Mar 02 '12