com.vaadin.data.validator.


Class AbstractValidator

java.lang.Object
  com.vaadin.data.validator.AbstractValidator

All Implemented Interfaces:

Validator, Serializable

Direct Known Subclasses:

AbstractStringValidator, CompositeValidator, StringLengthValidator

public abstract class AbstractValidator
extends Object
implements Validator

Abstract Validator implementation that provides a basic Validator implementation except the Validator.isValid(Object) method. Sub-classes need to implement the Validator.isValid(Object) method.

To include the value that failed validation in the exception message you can use "{0}" in the error message. This will be replaced with the failed value (converted to string using Object.toString()) or "null" if the value is null.

The default implementation of AbstractValidator does not support HTML in error messages. To enable HTML support, override InvalidValueException#getHtmlMessage() and throw such exceptions from validate(Object).

Since:

5.4

Version:

6.8.18

Author:

Vaadin Ltd.

See Also:

Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.data.Validator
Validator.EmptyValueException, Validator.InvalidValueException
 
Constructor Summary
AbstractValidator(String errorMessage)
          Constructs a validator with the given error message.
 
Method Summary
 String getErrorMessage()
          Returns the message to be included in the exception in case the value does not validate.
 void setErrorMessage(String errorMessage)
          Sets the message to be included in the exception in case the value does not validate.
 void validate(Object value)
          Checks the given value against this validator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.data.Validator
isValid
 

Constructor Detail

AbstractValidator

public AbstractValidator(String errorMessage)

Constructs a validator with the given error message.

Parameters:
errorMessage - the message to be included in an InvalidValueException (with "{0}" replaced by the value that failed validation).

Method Detail

validate

public void validate(Object value)
              throws Validator.InvalidValueException

Description copied from interface: Validator

Checks the given value against this validator. If the value is valid the method does nothing. If the value is invalid, an Validator.InvalidValueException is thrown.

Specified by:
validate in interface Validator

Parameters:
value - the value to check
Throws:
Validator.InvalidValueException - if the value is invalid

getErrorMessage

public String getErrorMessage()

Returns the message to be included in the exception in case the value does not validate.

Returns:
the error message provided in the constructor or using setErrorMessage(String).

setErrorMessage

public void setErrorMessage(String errorMessage)

Sets the message to be included in the exception in case the value does not validate. The exception message is typically shown to the end user.

Parameters:
errorMessage - the error message. "{0}" is automatically replaced by the value that did not validate.