|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Throwable java.lang.Exception org.springframework.validation.BindException
Default implementation of the Errors interface, supporting registration and evaluation of binding errors. Slightly unusual, as it is an exception.
This is mainly a framework-internal class. Normally, application
code will work with the Errors interface, or a DataBinder that in
turn exposes a BindException via getErrors()
.
Supports exporting a model, suitable for example for web MVC. Thus, it is sometimes used as parameter type instead of the Errors interface itself - if extracting the model makes sense in the respective context.
getModel()
,
DataBinder.getErrors()
,
Serialized FormField Summary | |
static java.lang.String |
ERROR_KEY_PREFIX
Prefix for the name of the Errors instance in a model, followed by the object name. |
Constructor Summary | |
BindException(java.lang.Object target,
java.lang.String name)
Create a new BindException instance. |
Method Summary | |
protected void |
addFieldError(FieldError fe)
Add a FieldError to the errors list. |
java.util.List |
getAllErrors()
Get all errors, both global and field ones. |
protected BeanWrapper |
getBeanWrapper()
Return the BeanWrapper that this instance uses. |
java.beans.PropertyEditor |
getCustomEditor(java.lang.String field)
|
int |
getErrorCount()
Return the total number of errors. |
FieldError |
getFieldError(java.lang.String field)
Get the first error associated with the given field, if any. |
int |
getFieldErrorCount(java.lang.String field)
Return the number of errors associated with the given field. |
java.util.List |
getFieldErrors(java.lang.String field)
Get all errors associated with the given field. |
java.lang.Object |
getFieldValue(java.lang.String field)
Return the current value of the given field, either the current bean property value or a rejected update from the last binding. |
ObjectError |
getGlobalError()
Get the first global error, if any. |
int |
getGlobalErrorCount()
Return the number of global (i.e. |
java.util.List |
getGlobalErrors()
Get all global errors. |
java.lang.String |
getMessage()
Returns diagnostic information about the errors held in this object. |
java.util.Map |
getModel()
Return a model Map for the obtained state, exposing an Errors instance as ' ERROR_KEY_PREFIX + objectName'
and the object itself. |
java.lang.String |
getNestedPath()
Return the current nested path of this Errors object. |
java.lang.String |
getObjectName()
Return the name of the bound object. |
java.lang.Object |
getTarget()
Return the wrapped target object. |
boolean |
hasErrors()
Return if there were any errors. |
boolean |
hasFieldErrors(java.lang.String field)
Return if there are any errors associated with the given field. |
boolean |
hasGlobalErrors()
Return if there were any global (i.e. |
void |
reject(java.lang.String errorCode,
java.lang.Object[] errorArgs,
java.lang.String defaultMessage)
Reject the current object, using the given error description. |
void |
reject(java.lang.String errorCode,
java.lang.String defaultMessage)
Reject the current object, using the given error description. |
void |
rejectValue(java.lang.String field,
java.lang.String errorCode,
java.lang.Object[] errorArgs,
java.lang.String defaultMessage)
Reject the given field of the current object, using the given error description. |
void |
rejectValue(java.lang.String field,
java.lang.String errorCode,
java.lang.String defaultMessage)
Reject the given field of the current object, using the given error description. |
void |
setNestedPath(java.lang.String nestedPath)
Allow context to be changed so that standard validators can validate subtrees. |
Methods inherited from class java.lang.Throwable |
fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String ERROR_KEY_PREFIX
Constructor Detail |
public BindException(java.lang.Object target, java.lang.String name)
target
- target object to bind ontoname
- name of the target objectMethod Detail |
protected BeanWrapper getBeanWrapper()
protected void addFieldError(FieldError fe)
public java.lang.Object getTarget()
public java.lang.String getObjectName()
Errors
getObjectName
in interface Errors
public void reject(java.lang.String errorCode, java.lang.String defaultMessage)
Errors
reject
in interface Errors
errorCode
- error code, interpretable as message keydefaultMessage
- fallback default messagepublic void reject(java.lang.String errorCode, java.lang.Object[] errorArgs, java.lang.String defaultMessage)
Errors
reject
in interface Errors
errorCode
- error code, interpretable as message keyerrorArgs
- error arguments, for argument binding via MessageFormat
(can be null)defaultMessage
- fallback default messagepublic void rejectValue(java.lang.String field, java.lang.String errorCode, java.lang.String defaultMessage)
Errors
rejectValue
in interface Errors
field
- field nameerrorCode
- error code, interpretable as message keydefaultMessage
- fallback default messagepublic void rejectValue(java.lang.String field, java.lang.String errorCode, java.lang.Object[] errorArgs, java.lang.String defaultMessage)
Errors
rejectValue
in interface Errors
field
- field nameerrorCode
- error code, interpretable as message keyerrorArgs
- error arguments, for argument binding via MessageFormat
(can be null)defaultMessage
- fallback default messagepublic boolean hasErrors()
Errors
hasErrors
in interface Errors
public int getErrorCount()
Errors
getErrorCount
in interface Errors
public java.util.List getAllErrors()
Errors
getAllErrors
in interface Errors
public boolean hasGlobalErrors()
Errors
hasGlobalErrors
in interface Errors
public int getGlobalErrorCount()
Errors
getGlobalErrorCount
in interface Errors
public java.util.List getGlobalErrors()
Errors
getGlobalErrors
in interface Errors
public ObjectError getGlobalError()
Errors
getGlobalError
in interface Errors
public boolean hasFieldErrors(java.lang.String field)
Errors
hasFieldErrors
in interface Errors
field
- field name
public int getFieldErrorCount(java.lang.String field)
Errors
getFieldErrorCount
in interface Errors
field
- field name
public java.util.List getFieldErrors(java.lang.String field)
Errors
getFieldErrors
in interface Errors
field
- field name
public FieldError getFieldError(java.lang.String field)
Errors
getFieldError
in interface Errors
public java.lang.Object getFieldValue(java.lang.String field)
Errors
getFieldValue
in interface Errors
field
- field name
public java.beans.PropertyEditor getCustomEditor(java.lang.String field)
public void setNestedPath(java.lang.String nestedPath)
Errors
For example, an address validator could validate the subobject "address" of a customer object.
setNestedPath
in interface Errors
nestedPath
- nested path within this object,
e.g. "address" (defaults to "", null is also acceptable).
Can end with a dot: both "address" and "address." are valid.public java.lang.String getNestedPath()
Errors
Returns a nested path with a dot, i.e. "address.", for easy building of concatenated paths. Default is an empty String.
getNestedPath
in interface Errors
public final java.util.Map getModel()
ERROR_KEY_PREFIX
+ objectName'
and the object itself.
Note that the Map is constructed each time you're calling this method, adding things to the map and then re-calling it will not do...
getObjectName()
,
ERROR_KEY_PREFIX
public java.lang.String getMessage()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |