net.databinder.valid.hib
Class DatabinderValidator

java.lang.Object
  extended by org.apache.wicket.validation.validator.AbstractValidator
      extended by net.databinder.valid.hib.DatabinderValidator
All Implemented Interfaces:
java.io.Serializable, org.apache.wicket.IClusterable, org.apache.wicket.validation.INullAcceptingValidator, org.apache.wicket.validation.IValidator, org.apache.wicket.validation.IValidatorAddListener

public class DatabinderValidator
extends org.apache.wicket.validation.validator.AbstractValidator
implements org.apache.wicket.validation.IValidatorAddListener

Checks a base model and property name against Hibernate Validator.

Author:
Nathan Hamblen
See Also:
Serialized Form

Nested Class Summary
static class DatabinderValidator.UnrecognizedModelException
           
 
Constructor Summary
DatabinderValidator()
          Construct instance that attempts to determine the base object and property to validate form the component it is added to.
DatabinderValidator(org.apache.wicket.model.IModel base, java.lang.String property)
          Validator for a property of an entity.
 
Method Summary
static void addTo(org.apache.wicket.markup.html.form.FormComponent formComponent)
          Add immediately to a form component.
 void onAdded(org.apache.wicket.Component component)
          Retains component for possible use in onValidate.
protected  void onValidate(org.apache.wicket.validation.IValidatable comp)
          Checks the component against Hibernate Validator.
 boolean validateOnNullValue()
           
 
Methods inherited from class org.apache.wicket.validation.validator.AbstractValidator
error, error, error, error, messageModel, resourceKey, resourceKey, validate, validate, variablesMap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabinderValidator

public DatabinderValidator(org.apache.wicket.model.IModel base,
                           java.lang.String property)
Validator for a property of an entity.

Parameters:
base - entity to validate
property - property of base to validate

DatabinderValidator

public DatabinderValidator()
Construct instance that attempts to determine the base object and property to validate form the component it is added to. This is only possible for components that depend on a parent CompoundPropertyModel or their own PropertyModels. The attempt is not made until the first validation check in onValidate(IValidatable) (to allow the full component hierarchy to be constructed). Do not use an instance for more than one component.

Method Detail

onValidate

protected void onValidate(org.apache.wicket.validation.IValidatable comp)
Checks the component against Hibernate Validator. If the base model and property were not supplied in the constructor, they will be determined from the component this validator was added to.

Specified by:
onValidate in class org.apache.wicket.validation.validator.AbstractValidator

onAdded

public void onAdded(org.apache.wicket.Component component)
Retains component for possible use in onValidate.

Specified by:
onAdded in interface org.apache.wicket.validation.IValidatorAddListener

validateOnNullValue

public boolean validateOnNullValue()
Overrides:
validateOnNullValue in class org.apache.wicket.validation.validator.AbstractValidator
Returns:
always true

addTo

public static void addTo(org.apache.wicket.markup.html.form.FormComponent formComponent)
Add immediately to a form component. Note that the component's model object must be available for inspection at this point or an exception will be thrown. (For a CompoundPropertyModel, this means the hierarchy must be established.) This is only possible for components that depend on a parent CompoundPropertyModel or their own PropertyModels.

Parameters:
formComponent - component to add validator to
Throws:
DatabinderValidator.UnrecognizedModelException - if no usable model is present


Copyright © 2005-2008 Nathan Hamblen. All Rights Reserved.