org.cruxframework.crux.core.client.controller
Annotation Type Validate


@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface Validate

This annotation can be used to set a validation method for an exposed controller method. It only makes any effect if used on exposed methods of a Controller class.

The validation method is executed before the exposed method annotated. If the validation method executes without any exception, the target exposed method is called, otherwise, Crux ValidationErrorHandler is called to handle the error reported by validation method, and the exposed method is not called.

See the following example:

 @Controller("myController")
 public class MyController
 {
    @Validate
    @Expose
    public void myEventHandler()
    {
        Window.alert("event dispatched!");
    }
    
    //Validate Method for myEventHandler method 
    public void validateMyEventHandler()
    {
        if (someTest)
      {
         throw new MyValidationException("Validation message");
      }
    }
 }
 
Any call made to the previous controller method (myEventHandler) will be preceded by a call to validation method (validateMyEventHandler). It applies to any event triggered by a .crux.xml or .view.xml page.

Validation method must obey the following constraints:

1) Be annotated with @Validate annotation.

2) Have at least package visibility.

3) Have no parameter or have only one parameter, with type equals to the type of the event handled by the method.

For example:

 @Controller("myController")
 public class MyController
 {
    @Validate
    @Expose
    public void myEventHandler(ClickEvent event)
    {
        Window.alert("event dispatched!");
    }
    
    //Validate Method for myEventHandler method 
    public void validateMyEventHandler(ClickEvent event)
    {
        if (someTest)
      {
         throw new MyValidationException("Validation message");
      }
    }
 }
 

Author:
Thiago da Rosa de Bustamante
See Also:
Expose, Controller

Optional Element Summary
 String value
          The name of the validation method that will be associated with the annotated method.
 

value

public abstract String value
The name of the validation method that will be associated with the annotated method. If not provided, Crux will use the following name convention: validate<MethodName>(First capitalized)

Default:
""


Copyright © 2014. All rights reserved.