Package org.apache.wicket.validation
Class Validatable<T>
- java.lang.Object
-
- org.apache.wicket.validation.Validatable<T>
-
- Type Parameters:
T- type of validatable
- All Implemented Interfaces:
IValidatable<T>
public class Validatable<T> extends Object implements IValidatable<T>
This implementation ofIValidatableis meant to be used outside of Wicket. It allows other parts of the application to utilizeIValidators 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 } } }- Since:
- 1.2.6
- Author:
- Igor Vaynberg (ivaynberg)
-
-
Constructor Summary
Constructors Constructor Description Validatable()Constructor.Validatable(T value)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiderror(IValidationError error)Reports an error against thisIValidatable's value.List<IValidationError>getErrors()Retrieves an unmodifiable list of any errors reported against thisIValidatableinstance.IModel<T>getModel()Returns the model of the component being validatedTgetValue()Retrieves the value to be validated.booleanisValid()Queries the current state of thisIValidatableinstance.voidsetModel(IModel<T> model)Sets modelvoidsetValue(T value)Sets the value object that will be returned bygetValue().
-
-
-
Constructor Detail
-
Validatable
public Validatable()
Constructor.
-
Validatable
public Validatable(T value)
Constructor.- Parameters:
value- The value that will be tested
-
-
Method Detail
-
setValue
public void setValue(T value)
Sets the value object that will be returned bygetValue().- Parameters:
value- the value object
-
getValue
public T getValue()
Description copied from interface:IValidatableRetrieves the value to be validated.- Specified by:
getValuein interfaceIValidatable<T>- Returns:
- the value to be validated
- See Also:
IValidatable.getValue()
-
error
public void error(IValidationError error)
Description copied from interface:IValidatableReports an error against thisIValidatable's value. Multiple errors can be reported by calling this method multiple times.- Specified by:
errorin interfaceIValidatable<T>- Parameters:
error- anIValidationErrorto be reported- See Also:
IValidatable.error(IValidationError)
-
getErrors
public List<IValidationError> getErrors()
Retrieves an unmodifiable list of any errors reported against thisIValidatableinstance.- Returns:
- an unmodifiable list of errors
-
isValid
public boolean isValid()
Description copied from interface:IValidatableQueries the current state of thisIValidatableinstance.IValidatables should assume they are valid untilIValidatable.error(IValidationError)is called.- Specified by:
isValidin interfaceIValidatable<T>- Returns:
trueif the object is in a valid state,falseif otherwise- See Also:
IValidatable.isValid()
-
getModel
public IModel<T> getModel()
Description copied from interface:IValidatableReturns the model of the component being validated- Specified by:
getModelin interfaceIValidatable<T>- Returns:
- component's model
-
-