org.apache.wicket.validation
Class Validatable

java.lang.Object
  extended by org.apache.wicket.validation.Validatable
All Implemented Interfaces:
IValidatable

public class Validatable
extends java.lang.Object
implements IValidatable

This implementation of 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
                }
        }
 }
 

Since:
1.2.6
Author:
Igor Vaynberg (ivaynberg)

Constructor Summary
Validatable()
          Constructor.
Validatable(java.lang.Object value)
          Constructor.
 
Method Summary
 void error(IValidationError error)
          Reports an error against this IValidatable's value.
 java.util.List getErrors()
          Retrieves an unmodifiable list of any errors reported against this IValidatable instance.
 java.lang.Object getValue()
          Retrieves the value to be validated.
 boolean isValid()
          Queries the current state of this IValidatable instance.
 void setValue(java.lang.Object value)
          Sets the value object that will be returned by getValue().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Validatable

public Validatable()
Constructor.


Validatable

public Validatable(java.lang.Object value)
Constructor.

Parameters:
value - The value that will be tested
Method Detail

setValue

public void setValue(java.lang.Object value)
Sets the value object that will be returned by getValue().

Parameters:
value - the value object

getValue

public java.lang.Object getValue()
Description copied from interface: IValidatable
Retrieves the value to be validated.

Specified by:
getValue in interface IValidatable
Returns:
the value to be validated
See Also:
IValidatable.getValue()

error

public void error(IValidationError error)
Description copied from interface: IValidatable
Reports an error against this IValidatable's value. Multiple errors can be reported by calling this method multiple times.

Specified by:
error in interface IValidatable
Parameters:
error - an IValidationError to be reported
See Also:
IValidatable.error(IValidationError)

getErrors

public java.util.List getErrors()
Retrieves an unmodifiable list of any errors reported against this IValidatable instance.

Returns:
an unmodifiable list of errors

isValid

public boolean isValid()
Description copied from interface: IValidatable
Queries the current state of this IValidatable instance. IValidatables should assume they are valid until IValidatable.error(IValidationError) is called.

Specified by:
isValid in interface IValidatable
Returns:
true if the object is in a valid state, false if otherwise
See Also:
IValidatable.isValid()


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.