com.avaje.ebean
Class InvalidValue

java.lang.Object
  extended by com.avaje.ebean.InvalidValue
All Implemented Interfaces:
Serializable

public class InvalidValue
extends Object

    
implements Serializable

    

Invalid value returned from validation rules.

An InvalidValue instance could be a simple Invalid Value or a container of "child invalid values".

Validation can recurse your entity bean object graph just like save() and as such a InvalidValue is actually a tree structure containing invalid values from each of the properties of a bean (which in turn could contain invalid values etc etc).

To get the simple list of invalid values use ... ValidationException.getErrors() or getErrors() method.

Validation rules can fire automatically on Ebean.save() which you can turn on or off. You can also use Ebean.validate(Object) to validate a bean or Ebean.validate(Object, String, Object) to validate a specific property.

InvalidValue objects can be retrieved via ValidationException.getErrors() or via getErrors()

  ## turn on automatic validation for Ebean.save()
 ebean.validation=true
 
  ## turn on automatic creation of not null validation
  ## and max length validation for varchar's based on 
  ## database meta data (no annotations required)
 ebean.validation.autocreate=true
 
 ## for more specific control... 
 ## 
 ## ebean.validation.autocreate.notnull=true
 ## ebean.validation.autocreate.length=true
 ## ebean.validation.autocreate.length.max=4000
 ## NB: Only auto create length validation for
 ## varchar columns less than 4000 characters
 

See Also:
Serialized Form

Constructor Summary
InvalidValue(String validatorKey, Object[] validatorAttributes, String beanType, String propertyName, Object value)
           
InvalidValue(String validatorKey, String beanType, Object bean, InvalidValue[] children)
           
 
Method Summary
 String getBeanType()
           
 InvalidValue[] getChildren()
          Returns children when validation recurses.
 InvalidValue[] getErrors()
          Return a flat list of the errors.
 String getMessage()
          Return a user error message.
 String getPropertyName()
          Return the property name.
 Object[] getValidatorAttributes()
          Returns the attributes of the validator.
 String getValidatorKey()
          Return the key of the validator that caused this InvalidValue.
 Object getValue()
          Return the value deemed invalid.
 boolean isBean()
          Returns true if this represents a bean with a list of property errors.
 boolean isError()
          Returns true if this is a an error on a property.
 void setMessage(String message)
          Set a user error message.
static InvalidValue[] toArray(List<InvalidValue> list)
          Helper method to convert a list to an array.
static List<InvalidValue> toList(InvalidValue invalid)
          Helper method to convert a recursive error into a list.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InvalidValue

public InvalidValue(String validatorKey,
                    String beanType,
                    Object bean,
                    InvalidValue[] children)

InvalidValue

public InvalidValue(String validatorKey,
                    Object[] validatorAttributes,
                    String beanType,
                    String propertyName,
                    Object value)
Method Detail

getBeanType

public String getBeanType()

getPropertyName

public String getPropertyName()
Return the property name.


getValidatorKey

public String getValidatorKey()
Return the key of the validator that caused this InvalidValue.


getValidatorAttributes

public Object[] getValidatorAttributes()
Returns the attributes of the validator. For example, this is the min, max of the range validator.

If there are no attributes (like NotNull) then an empty array is returned.

These attributes can be used with the propertyName and validatorKey to build a nice error message for the user.


getValue

public Object getValue()
Return the value deemed invalid.


getChildren

public InvalidValue[] getChildren()
Returns children when validation recurses.


getMessage

public String getMessage()
Return a user error message.


setMessage

public void setMessage(String message)
Set a user error message.


isBean

public boolean isBean()
Returns true if this represents a bean with a list of property errors.

Note that this is recursive (can follow associated beans or collections) so some of the children could in fact be other beans with errors themselves.


isError

public boolean isError()
Returns true if this is a an error on a property.


getErrors

public InvalidValue[] getErrors()
Return a flat list of the errors.


toString

public String toString()
Overrides:
toString in class Object

toArray

public static InvalidValue[] toArray(List<InvalidValue> list)
Helper method to convert a list to an array.


toList

public static List<InvalidValue> toList(InvalidValue invalid)
Helper method to convert a recursive error into a list.



Copyright © 2010. All Rights Reserved.