facet classafFormBean::Validate
sys::Obj afFormBean::Validate : sys::Facet
Place on a method of a FormBean to have it take part in server side validation. Validate methods should be static and take a single FormField parameter. They should inspect the formField.value and set an errMsg if invalid. Example:
class User {
Str? name
@Validate { field=#name }
static Void validateName(FormField formField) {
if (formField.formValue == "Trisha")
formField.errMsg = "Ex-girlfriends not allowed!"
}
}
If @Validate.field is null then the first parameter should be FormBean:
@Validate
static Void validateBean(FormBean formBean) { ... }
FormBean validation is performed after FormField validation.
Note that validation methods are called using IoC, so services may be passed in as extra method parameters:
@Validate
static Void validateName(FormField formField, MyService service) { ... }