T
- The typepublic abstract class AbstractValidator<T> extends Object implements Validator
Validator
implementation that
provides a basic Validator implementation except the
isValidValue(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 Vaadin 7, subclasses can either implement validate(Object)
directly or implement isValidValue(Object)
when migrating legacy
applications. To check validity, validate(Object)
should be used.
Validator.EmptyValueException, Validator.InvalidValueException
Constructor and Description |
---|
AbstractValidator(String errorMessage)
Constructs a validator with the given error message.
|
Modifier and Type | Method and Description |
---|---|
String |
getErrorMessage()
Returns the message to be included in the exception in case the value
does not validate.
|
abstract Class<T> |
getType() |
boolean |
isValid(Object value)
Since Vaadin 7, subclasses of AbstractValidator should override
isValidValue(Object) or validate(Object) instead of
isValid(Object) . |
protected boolean |
isValidType(Object value)
Checks the type of the value to validate to ensure it conforms with
getType.
|
protected abstract boolean |
isValidValue(T value)
Internally check the validity of a value.
|
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.
|
public AbstractValidator(String errorMessage)
errorMessage
- the message to be included in an InvalidValueException
(with "{0}" replaced by the value that failed validation).public boolean isValid(Object value)
isValidValue(Object)
or validate(Object)
instead of
isValid(Object)
. validate(Object)
should normally be
used to check values.value
- protected abstract boolean isValidValue(T value)
validate(Object)
and the return value of this method is ignored.
This method should not be called from outside the validator class itself.value
- public void validate(Object value) throws Validator.InvalidValueException
Validator
Validator.InvalidValueException
is thrown.validate
in interface Validator
value
- the value to checkValidator.InvalidValueException
- if the value is invalidprotected boolean isValidType(Object value)
value
- The value to checkgetType()
public String getErrorMessage()
setErrorMessage(String)
.public void setErrorMessage(String errorMessage)
errorMessage
- the error message. "{0}" is automatically replaced by the
value that did not validate.Copyright © 2016 Vaadin Ltd. All rights reserved.