Class BeanValidator

java.lang.Object
org.zkoss.bind.validator.AbstractValidator
org.zkoss.bind.validator.BeanValidator
org.zkoss.zkmax.bind.BeanValidator
All Implemented Interfaces:
org.zkoss.bind.Validator

public class BeanValidator extends org.zkoss.bind.validator.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 Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Object[]
    getValidationInfo(org.zkoss.bind.ValidationContext ctx, Object base, 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BeanValidator

      public BeanValidator()
  • Method Details

    • getValidationInfo

      protected Object[] getValidationInfo(org.zkoss.bind.ValidationContext ctx, Object base, 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 org.zkoss.bind.validator.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