com.vaadin.data.validator.
Class AbstractValidator
java.lang.Object
com.vaadin.data.validator.AbstractValidator
All Implemented Interfaces:
Direct Known Subclasses:
AbstractStringValidator, CompositeValidator, StringLengthValidator
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:
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)
- Parameters:
errorMessage
- the message to be included in anInvalidValueException
(with "{0}" replaced by the value that failed validation).
Constructs a validator with the given error message.
Method Detail |
---|
validate
public void validate(Object value)
throws Validator.InvalidValueException
- Parameters:
value
- the value to check- Throws:
Validator.InvalidValueException
- if the value is invalid
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.
getErrorMessage
public String getErrorMessage()
- Returns:
- the error message provided in the constructor or using
setErrorMessage(String)
.
Returns the message to be included in the exception in case the value does not validate.
setErrorMessage
public void setErrorMessage(String errorMessage)
- Parameters:
errorMessage
- the error message. "{0}" is automatically replaced by the value that did not validate.
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.