wicket.markup.html.form.validation
Class AbstractValidator

java.lang.Object
  extended by wicket.markup.html.form.validation.AbstractValidator
All Implemented Interfaces:
java.io.Serializable, IValidator
Direct Known Subclasses:
DateValidator, LengthValidator, NumberValidator, RequiredValidator, 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(FormComponent ...) 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 key that is used to get the message defaults to the pattern: [form-name].[component-name].[validator-class]. For example:

MyForm.name.RequiredValidator=A name is required.

Error message string resources can contain optional property 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

Constructor Summary
AbstractValidator()
           
 
Method Summary
 void error(FormComponent formComponent)
          Sets an error on the component being validated using the map returned by messageModel() for variable interpolations.
 void error(FormComponent formComponent, java.util.Map map)
          Sets an error on the component being validated using the given map for variable interpolations.
 void error(FormComponent formComponent, java.lang.String resourceKey, IModel resourceModel)
          Returns a formatted validation error message for a given component.
 void error(FormComponent formComponent, java.lang.String resourceKey, java.util.Map map)
          Sets an error on the component being validated using the given map for variable interpolations.
protected  java.util.Map messageModel(FormComponent formComponent)
          Gets the default variables for interpolation.
protected  java.lang.String resourceKey(FormComponent formComponent)
          Gets the resource key for validator's error message from the ApplicationSettings class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface wicket.markup.html.form.validation.IValidator
validate
 

Constructor Detail

AbstractValidator

public AbstractValidator()
Method Detail

error

public void error(FormComponent formComponent)
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.

Parameters:
formComponent - form component

error

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

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

error

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

Parameters:
formComponent - form component
map - The model for variable interpolation

error

public void error(FormComponent formComponent,
                  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. If that one is null the default one is created from messageModel(formComponent)

Parameters:
formComponent - form component
resourceKey - The resource key to use
resourceModel - The model for variable interpolation, it needs to have a map inside it.

resourceKey

protected java.lang.String resourceKey(FormComponent formComponent)
Gets the resource key for validator's error message from the ApplicationSettings class.

Parameters:
formComponent - form component that is being validated
Returns:
the resource key based on the form component

messageModel

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

Parameters:
formComponent - form component
Returns:
a map with the variables for interpolation


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