wicket.markup.html.form.validation
Class AbstractValidator

java.lang.Object
  extended bywicket.markup.html.form.validation.AbstractValidator
All Implemented Interfaces:
IValidator, java.io.Serializable
Direct Known Subclasses:
StringValidator

public abstract class AbstractValidator
extends java.lang.Object
implements IValidator

Base class for form component validators. This class is thread-safe and therefore it is safe to share validators across sessions/threads.

Error messages can be registered on a component by calling one of the error() overloads. The error message will be retrieved using the Localizer for the form component. Normally, this localizer will find the error message in a string resource bundle (properties file) associated with the page in which this validator is contained. The resource key must be of the form: [form-name].[component-name].[validator-class]. For example:

MyForm.name.RequiredValidator=A name is required.

Error message string resources can contain optional ognl variable interpolations from the component, such as:

editBook.name.LengthValidator='${input}' is too short a name.

Available variables for interpolation are:

but specific validator subclasses may add more values.

Author:
Jonathan Locke, Eelco Hillenius
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class wicket.markup.html.form.validation.IValidator
IValidator.NullValidator
 
Field Summary
 
Fields inherited from interface wicket.markup.html.form.validation.IValidator
NULL
 
Constructor Summary
AbstractValidator()
           
 
Method Summary
 void error()
          Sets an error on the component being validated using the map returned by messageModel() for variable interpolations.
 void error(java.util.Map map)
          Sets an error on the component being validated using the given map for variable interpolations.
 void error(java.lang.String resourceKey, IModel resourceModel)
          Returns a formatted validation error message for a given component.
 void error(java.lang.String resourceKey, java.util.Map map)
          Sets an error on the component being validated using the given map for variable interpolations.
 FormComponent getFormComponent()
           
 java.lang.String getInput()
           
protected  java.util.Map messageModel()
          Gets the default variables for interpolation.
abstract  void onValidate()
          Implemented by subclasses to validate component
protected  java.lang.String resourceKey()
          Gets the resource key based on the form component.
 void validate(FormComponent formComponent)
          THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
 
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

error

public void error()
Sets an error on the component being validated using the map returned by messageModel() for variable interpolations.

See class comments for details about how error messages are loaded and formatted.


error

public void error(java.lang.String resourceKey,
                  IModel resourceModel)
Returns a formatted validation error message for a given component. The error message is retrieved from a message bundle associated with the page in which this validator is contained using the given resource key. The resourceModel is used for variable interpolation.

Parameters:
resourceKey - The resource key to use
resourceModel - The model for variable interpolation

error

public void error(java.lang.String resourceKey,
                  java.util.Map map)
Sets an error on the component being validated using the given map for variable interpolations.

Parameters:
resourceKey - The resource key to use
map - The model for variable interpolation

error

public void error(java.util.Map map)
Sets an error on the component being validated using the given map for variable interpolations.

Parameters:
map - The model for variable interpolation

getFormComponent

public FormComponent getFormComponent()
Returns:
Returns the component.

getInput

public java.lang.String getInput()
Returns:
The string value being validated

onValidate

public abstract void onValidate()
Implemented by subclasses to validate component


validate

public final void validate(FormComponent formComponent)
Description copied from interface: IValidator
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT IMPLEMENT IT.

Instead of subclassing IValidator, you should use one of the existing validators, which cover a huge number of cases, or if none satisfies your need, subclass CustomValidator.

Validates the given input. The input corresponds to the input from the request for a component. Any implementation of this method should be synchronized because validators are intended to be shared across sessions/threads.

Specified by:
validate in interface IValidator
Parameters:
formComponent - Component to validate
See Also:
IValidator.validate(wicket.markup.html.form.FormComponent)

messageModel

protected java.util.Map messageModel()
Gets the default variables for interpolation. These are:

Returns:
a map with the variables for interpolation

resourceKey

protected java.lang.String resourceKey()
Gets the resource key based on the form component. It will have the form: [form-name].[component-name].[validator-class]

Returns:
the resource key based on the form component


Copyright © 2004-2005 Wicket developers. All Rights Reserved.