Package org.zkoss.zkmax.bind
Class BeanValidator
- java.lang.Object
-
- org.zkoss.bind.validator.AbstractValidator
-
- org.zkoss.bind.validator.BeanValidator
-
- org.zkoss.zkmax.bind.BeanValidator
-
- All Implemented Interfaces:
Validator
public class BeanValidator extends BeanValidator
A JSR 303 compatible validator for a property-binding. Notice : Before use this validator, you have to configure your environment (depends on the implementation you chosen). Here is a article Integrate ZK with JSR 303: Bean Validation talks about how to set up JSR 303 in ZK with Hibernate implementation. It validates a single property of a bean and sets the invalid message byAbstractValidator.addInvalidMessage(ValidationContext, String)
. To use this class, you have to add@validator('beanValidator')
or@validator('org.zkoss.zkmax.bind.BeanValidator')
to the property-binding Example
It also supports to validate a property of a form which properties are load from a bean, It uses the class of last loaded bean of the form to perform the validation, which means it doesn't support to validate a form that didn't loaded a bean yet. Example<grid width="600px"> <textbox id="tb" value="@bind(vm.person.firstName) @validator('beanValidator')"/> <label value="@load(vmsgs[tb])"/> </grid>
<grid width="600px" form="@id('fx') @load(vm.user) @save(vm.user,after='save')"> <textbox id="tb" value="@bind(fx.firstName) @validator('beanValidator')"/> <label value="@load(vmsgs[tb])"/> </grid>
- Since:
- 6.0.1
- Author:
- dennis
-
-
Constructor Summary
Constructors Constructor Description BeanValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object[]
getValidationInfo(ValidationContext ctx, java.lang.Object base, java.lang.String property)
Get the bean class of the base object and property to validate.-
Methods inherited from class org.zkoss.bind.validator.BeanValidator
getValidator, handleConstraintViolation, sort, validate, validate
-
Methods inherited from class org.zkoss.bind.validator.AbstractValidator
addInvalidMessage, addInvalidMessage, addInvalidMessage, addInvalidMessages, addInvalidMessages, addInvalidMessages
-
-
-
-
Method Detail
-
getValidationInfo
protected java.lang.Object[] getValidationInfo(ValidationContext ctx, java.lang.Object base, java.lang.String property)
Get the bean class of the base object and property to validate.
By default, if the base object is a form(implements FormExt), it returns the last loaded bean class of this form.
If the object is not a form, it returns the class of base object directly.- Overrides:
getValidationInfo
in classBeanValidator
- Parameters:
ctx
- the validation contextbase
- the base objectproperty
- the property to validate- Returns:
- a object array, the first item is the bean class of base object, 2nd item is the tuned property regards to the bean class
-
-