Class 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 by AbstractValidator.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

    
     <grid width="600px">
       <textbox id="tb" value="@bind(vm.person.firstName) @validator('beanValidator')"/>
       <label value="@load(vmsgs[tb])"/> 
    </grid>
     
    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" 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 Detail

      • BeanValidator

        public BeanValidator()
    • 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 class BeanValidator
        Parameters:
        ctx - the validation context
        base - the base object
        property - 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