0

ZK 6 Validator (New Feature)

asked 2012-02-10 16:24:11 +0800

shumy gravatar image shumy
244 1

updated 2012-02-10 16:25:22 +0800

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);
} 

Something similar to this.
The point is, it can be simplified using the power of annotations as you already use in other places.

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest
link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-02-10 16:24:11 +0800

Seen: 471 times

Last updated: Mar 02 '12

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