org.apache.wicket.validation.validator
Class AbstractValidator<T>

java.lang.Object
  extended by org.apache.wicket.behavior.Behavior
      extended by org.apache.wicket.validation.validator.AbstractValidator<T>
Type Parameters:
T - type of validatable
All Implemented Interfaces:
java.io.Serializable, IClusterable, IComponentAwareEventSink, IComponentAwareHeaderContributor, INullAcceptingValidator<T>, IValidator<T>
Direct Known Subclasses:
CreditCardValidator, DateValidator, StringValidator, UrlValidator

public abstract class AbstractValidator<T>
extends Behavior
implements INullAcceptingValidator<T>, IClusterable

Convenience base class for IValidators. This class is thread-safe and therefore it is safe to share validators across sessions/threads.

Error messages can be registered by calling one of the error (IValidatable) overloads. By default this class will skip validation if the IValidatable.getValue() returns null. Validators that wish to validate the null value need to override validateOnNullValue() and return true.

Since:
1.2.6
Author:
Jonathan Locke, Eelco Hillenius, Igor Vaynberg (ivaynberg)
See Also:
Serialized Form

Constructor Summary
AbstractValidator()
           
 
Method Summary
 void error(IValidatable<T> validatable)
          Reports an error against an IValidatable instance using the Map returned by variablesMap(IValidatable) for variable interpolations and the message resource key returned by resourceKey().
 void error(IValidatable<T> validatable, java.util.Map<java.lang.String,java.lang.Object> vars)
          Reports an error against an IValidatable instance using the given Map for variable interpolations and message resource key provided by resourceKey().
 void error(IValidatable<T> validatable, java.lang.String resourceKey)
          Reports an error against an IValidatable instance using the Map returned by variablesMap(IValidatable) for variable interpolations and the given message resource key.
 void error(IValidatable<T> validatable, java.lang.String resourceKey, java.util.Map<java.lang.String,java.lang.Object> vars)
          Reports an error against an IValidatable instance using the given message resource key and Map for variable interpolations.
protected abstract  void onValidate(IValidatable<T> validatable)
          Validates the IValidatable instance.
protected  java.lang.String resourceKey()
          Gets the message resource key for this validator's error message from the ApplicationSettings class.
 void validate(IValidatable<T> validatable)
          Validates the IValidatable instance.
 boolean validateOnNullValue()
          Indicates whether or not to validate the value if it is null.
protected  java.util.Map<java.lang.String,java.lang.Object> variablesMap(IValidatable<T> validatable)
          Gets the default Map of variables.
 
Methods inherited from class org.apache.wicket.behavior.Behavior
afterRender, beforeRender, bind, canCallListenerInterface, detach, getStatelessHint, isEnabled, isTemporary, onComponentTag, onConfigure, onEvent, onException, renderHead, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractValidator

public AbstractValidator()
Method Detail

validateOnNullValue

public boolean validateOnNullValue()
Indicates whether or not to validate the value if it is null. It is usually desirable to skip validation if the value is null, unless we want to make sure the value is in fact null (a rare use case). Validators that extend this and wish to ensure the value is null should override this method and return true.

Returns:
true to validate on null value, false to skip validation on null value

onValidate

protected abstract void onValidate(IValidatable<T> validatable)
Validates the IValidatable instance.

Parameters:
validatable - the given IValidatable instance

validate

public final void validate(IValidatable<T> validatable)
Description copied from interface: IValidator
Validates the IValidatable instance. Validation errors should be reported using the IValidatable.error(IValidationError) method.

Specified by:
validate in interface IValidator<T>
Parameters:
validatable - the IValidatable instance being validated
See Also:
IValidator.validate(IValidatable)

error

public void error(IValidatable<T> validatable)
Reports an error against an IValidatable instance using the Map returned by variablesMap(IValidatable) for variable interpolations and the message resource key returned by resourceKey().

Parameters:
validatable - the IValidatable instance being validated

error

public void error(IValidatable<T> validatable,
                  java.lang.String resourceKey)
Reports an error against an IValidatable instance using the Map returned by variablesMap(IValidatable) for variable interpolations and the given message resource key.

Parameters:
validatable - the IValidatable instance being validated
resourceKey - the message resource key to use

error

public void error(IValidatable<T> validatable,
                  java.util.Map<java.lang.String,java.lang.Object> vars)
Reports an error against an IValidatable instance using the given Map for variable interpolations and message resource key provided by resourceKey().

Parameters:
validatable - the IValidatable instance being validated
vars - Map of variables for variable interpolation

error

public void error(IValidatable<T> validatable,
                  java.lang.String resourceKey,
                  java.util.Map<java.lang.String,java.lang.Object> vars)
Reports an error against an IValidatable instance using the given message resource key and Map for variable interpolations.

Parameters:
validatable - the IValidatable instance being validated
resourceKey - the message resource key to use
vars - Map of variables for variable interpolation

resourceKey

protected java.lang.String resourceKey()
Gets the message resource key for this validator's error message from the ApplicationSettings class. NOTE: THIS METHOD SHOULD NEVER RETURN null.

Returns:
the message resource key for this validator

variablesMap

protected java.util.Map<java.lang.String,java.lang.Object> variablesMap(IValidatable<T> validatable)
Gets the default Map of variables. NOTE: THIS METHOD SHOULD NEVER RETURN null.

Parameters:
validatable - the IValidatable instance being validated
Returns:
a Map of variables for variable interpolation


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.