|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.avaje.ebean.InvalidValue
public class InvalidValue
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
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 |
---|
public InvalidValue(String validatorKey, String beanType, Object bean, InvalidValue[] children)
public InvalidValue(String validatorKey, Object[] validatorAttributes, String beanType, String propertyName, Object value)
Method Detail |
---|
public String getBeanType()
public String getPropertyName()
public String getValidatorKey()
public Object[] getValidatorAttributes()
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.
public Object getValue()
public InvalidValue[] getChildren()
public String getMessage()
public void setMessage(String message)
public boolean isBean()
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.
public boolean isError()
public InvalidValue[] getErrors()
public String toString()
toString
in class Object
public static InvalidValue[] toArray(List<InvalidValue> list)
public static List<InvalidValue> toList(InvalidValue invalid)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |