Class Validatable<T>

  • Type Parameters:
    T - type of validatable
    All Implemented Interfaces:
    IValidatable<T>

    public class Validatable<T>
    extends java.lang.Object
    implements IValidatable<T>
    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

      Constructors 
      Constructor Description
      Validatable()
      Constructor.
      Validatable​(T value)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void error​(IValidationError error)
      Reports an error against this IValidatable's value.
      java.util.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().
      • 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​(T value)
        Constructor.
        Parameters:
        value - The value that will be tested
    • Method Detail

      • setModel

        public void setModel​(IModel<T> model)
        Sets model
        Parameters:
        model -
      • setValue

        public void setValue​(T value)
        Sets the value object that will be returned by getValue().
        Parameters:
        value - the value object
      • getErrors

        public java.util.List<IValidationError> getErrors()
        Retrieves an unmodifiable list of any errors reported against this IValidatable instance.
        Returns:
        an unmodifiable list of errors
      • getModel

        public IModel<T> getModel()
        Description copied from interface: IValidatable
        Returns the model of the component being validated
        Specified by:
        getModel in interface IValidatable<T>
        Returns:
        component's model