Package org.zkoss.zkmax.bind
Class FormBeanValidator
java.lang.Object
org.zkoss.bind.validator.AbstractValidator
org.zkoss.zkmax.bind.FormBeanValidator
- All Implemented Interfaces:
org.zkoss.bind.Validator
public class FormBeanValidator
extends org.zkoss.bind.validator.AbstractValidator
A JSR 303 compatible validator for a form-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 all the saving properties of a bean and sets the invalid message by
AbstractValidator.addInvalidMessage(ValidationContext, String, String).
To use this class, you have to add @validator('formBeanValidator',prefix='p_') or @validator('org.zkoss.zkoss.bind.FormBeanValidator',prefix='p_') to the form-binding,
where prefix is an argument of the message name(prefix+property) for a property.
Because of the message name is shared between same ValidationMessages, that is same Binder,
you have to provide a unique prefix for every FormBeanValidator in same binder.
Example
<grid width="600px" form="@id('fx') @load(vm.user) @save(vm.user,after='save') @validator('formBeanValidator',prefix='p_')">
<textbox value="@bind(fx.firstName)"/>
<label value="@load(vmsgs['p_firstName'])"/>
</grid>
- Since:
- 6.0.1
- Author:
- dennis
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ClassgetBeanClass(org.zkoss.bind.ValidationContext ctx, Object base) Get the bean class of the base object.protected jakarta.validation.Validatorprotected voidhandleConstraintViolation(org.zkoss.bind.ValidationContext ctx, String key, Set<jakarta.validation.ConstraintViolation<?>> violations) Handle hibernate ConstraintViolation.protected voidSort the violations, make multiple violation order more predictable.protected Set<jakarta.validation.ConstraintViolation<?>>Validate the valuevoidvalidate(org.zkoss.bind.ValidationContext ctx) Methods inherited from class org.zkoss.bind.validator.AbstractValidator
addInvalidMessage, addInvalidMessage, addInvalidMessage, addInvalidMessages, addInvalidMessages, addInvalidMessages
-
Constructor Details
-
FormBeanValidator
public FormBeanValidator()
-
-
Method Details
-
getValidator
protected jakarta.validation.Validator getValidator() -
validate
protected Set<jakarta.validation.ConstraintViolation<?>> validate(Class clz, String property, Object value) Validate the value- Parameters:
clz- the class of beanproperty- the property of beanvalue- the value to be validated.- Returns:
- the ConstraintViolation set.
-
validate
public void validate(org.zkoss.bind.ValidationContext ctx) -
sort
Sort the violations, make multiple violation order more predictable. By default, sort it by the constraint name.- Parameters:
viloations-
-
handleConstraintViolation
protected void handleConstraintViolation(org.zkoss.bind.ValidationContext ctx, String key, Set<jakarta.validation.ConstraintViolation<?>> violations) Handle hibernate ConstraintViolation. By default, it adds to invalid messages.- Parameters:
ctx-key- the key of messageviolations-- Since:
- 6.0.1
-
getBeanClass
Get the bean class of the base object.- Parameters:
ctx- the validation contextbase- the base object- Returns:
- the bean class of base object, never null
-