T - type of validatablepublic class Validatable<T> extends Object implements IValidatable<T>
IValidatable is meant to be used outside of Wicket. It allows
other parts of the application to utilize IValidators for validation.
Example:
class WebService
{
public void addUser(String firstName, String lastName)
{
Validatable standin = new Validatable();
standin.setValue(firstName);
new FirstNameValidator().validate(standin);
standing.setValue(lastName);
new LastNameValidator().validate(standin);
if (!standin.isValid())
{
// roll your own ValidationException
throw new ValidationException(standin.getErrors());
}
else
{
// add user here
}
}
}
| Constructor and Description |
|---|
Validatable()
Constructor.
|
Validatable(T value)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
error(IValidationError error)
Reports an error against this
IValidatable's value. |
List<IValidationError> |
getErrors()
Retrieves an unmodifiable list of any errors reported against this
IValidatable
instance. |
IModel<T> |
getModel()
Returns the model of the component being validated
|
T |
getValue()
Retrieves the value to be validated.
|
boolean |
isValid()
Queries the current state of this
IValidatable instance. |
void |
setModel(IModel<T> model)
Sets model
|
void |
setValue(T value)
Sets the value object that will be returned by
getValue(). |
public Validatable()
public Validatable(T value)
value - The value that will be testedpublic void setValue(T value)
getValue().value - the value objectpublic T getValue()
IValidatablegetValue in interface IValidatable<T>IValidatable.getValue()public void error(IValidationError error)
IValidatableIValidatable's value. Multiple errors can be
reported by calling this method multiple times.error in interface IValidatable<T>error - an IValidationError to be reportedIValidatable.error(IValidationError)public List<IValidationError> getErrors()
IValidatable
instance.public boolean isValid()
IValidatableIValidatable instance.
IValidatables should assume they are valid until
IValidatable.error(IValidationError) is called.isValid in interface IValidatable<T>true if the object is in a valid state, false if otherwiseIValidatable.isValid()public IModel<T> getModel()
IValidatablegetModel in interface IValidatable<T>Copyright © 2006–2014 Apache Software Foundation. All rights reserved.