Class BeanValidator

  extended by org.zkoss.bind.validator.AbstractValidator
      extended by org.zkoss.bind.validator.BeanValidator
          extended by org.zkoss.zkmax.bind.BeanValidator
All Implemented Interfaces:

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


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


<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])"/> 


Constructor Summary
Method Summary
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, addInvalidMessages, addInvalidMessages
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public BeanValidator()
Method Detail


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.

getValidationInfo in class BeanValidator
ctx - the validation context
base - the base object
property - the property to validate
a object array, the first item is the bean class of base object, 2nd item is the tuned property regards to the bean class

Copyright © 2005-2011 Potix Corporation. All Rights Reserved. Logo