Class AbstractErrors
- All Implemented Interfaces:
- Serializable,- Errors
- Direct Known Subclasses:
- AbstractBindingResult
Errors interface.
 Provides nested path handling but does not define concrete management
 of ObjectErrors and FieldErrors.- Since:
- 2.5.3
- Author:
- Juergen Hoeller, Rossen Stoyanchev
- See Also:
- 
Field SummaryFields inherited from interface org.springframework.validation.ErrorsNESTED_PATH_SEPARATOR
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected StringcanonicalFieldName(String field) Determine the canonical field name for the given field.protected voiddoSetNestedPath(String nestedPath) Actually set the nested path.protected StringfixedField(String field) Transform the given field into its full path, regarding the nested path of this instance.Get all errors, both global and field ones.intDetermine the total number of errors.Get the first error associated with a field, if any.getFieldError(String field) Get the first error associated with the given field, if any.intDetermine the number of errors associated with a field.intgetFieldErrorCount(String field) Determine the number of errors associated with the given field.getFieldErrors(String field) Get all errors associated with the given field.Class<?>getFieldType(String field) Determine the type of the given field, as far as possible.Get the first global error, if any.intDetermine the number of global errors.Return the current nested path of thisErrorsobject.booleanDetermine if there were any errors.booleanDetermine if there were any errors associated with a field.booleanhasFieldErrors(String field) Determine if there were any errors associated with the given field.booleanDetermine if there were any global errors.protected booleanisMatchingFieldError(String field, FieldError fieldError) Check whether the given FieldError matches the given field.voidPop the former nested path from the nested path stack.voidpushNestedPath(String subPath) Push the given sub path onto the nested path stack.voidRegister a global error for the entire target object, using the given error description.voidRegister a global error for the entire target object, using the given error description.voidrejectValue(String field, String errorCode) Register a field error for the specified field of the current object (respecting the current nested path, if any), using the given error description.voidrejectValue(String field, String errorCode, String defaultMessage) Register a field error for the specified field of the current object (respecting the current nested path, if any), using the given error description.voidsetNestedPath(String nestedPath) Allow context to be changed so that standard validators can validate subtrees.toString()Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.validation.ErrorsaddAllErrors, getFieldErrors, getFieldValue, getGlobalErrors, getObjectName, reject, rejectValue
- 
Constructor Details- 
AbstractErrorspublic AbstractErrors()
 
- 
- 
Method Details- 
setNestedPathDescription copied from interface:ErrorsAllow context to be changed so that standard validators can validate subtrees. Reject calls prepend the given path to the field names.For example, an address validator could validate the subobject "address" of a customer object. - Specified by:
- setNestedPathin interface- Errors
- Parameters:
- nestedPath- nested path within this object, e.g. "address" (defaults to "",- nullis also acceptable). Can end with a dot: both "address" and "address." are valid.
- See Also:
 
- 
getNestedPathDescription copied from interface:ErrorsReturn the current nested path of thisErrorsobject.Returns a nested path with a dot, i.e. "address.", for easy building of concatenated paths. Default is an empty String. - Specified by:
- getNestedPathin interface- Errors
- See Also:
 
- 
pushNestedPathDescription copied from interface:ErrorsPush the given sub path onto the nested path stack.A Errors.popNestedPath()call will reset the original nested path before the correspondingpushNestedPath(String)call.Using the nested path stack allows to set temporary nested paths for subobjects without having to worry about a temporary path holder. For example: current path "spouse.", pushNestedPath("child") → result path "spouse.child."; popNestedPath() → "spouse." again. - Specified by:
- pushNestedPathin interface- Errors
- Parameters:
- subPath- the sub path to push onto the nested path stack
- See Also:
 
- 
popNestedPathDescription copied from interface:ErrorsPop the former nested path from the nested path stack.- Specified by:
- popNestedPathin interface- Errors
- Throws:
- IllegalStateException- if there is no former nested path on the stack
- See Also:
 
- 
doSetNestedPathActually set the nested path. Delegated to by setNestedPath and pushNestedPath.
- 
fixedFieldTransform the given field into its full path, regarding the nested path of this instance.
- 
canonicalFieldNameDetermine the canonical field name for the given field.The default implementation simply returns the field name as-is. - Parameters:
- field- the original field name
- Returns:
- the canonical field name
 
- 
rejectDescription copied from interface:ErrorsRegister a global error for the entire target object, using the given error description.
- 
rejectDescription copied from interface:ErrorsRegister a global error for the entire target object, using the given error description.
- 
rejectValueDescription copied from interface:ErrorsRegister a field error for the specified field of the current object (respecting the current nested path, if any), using the given error description.The field name may be nullor empty String to indicate the current object itself rather than a field of it. This may result in a corresponding field error within the nested object graph or a global error if the current object is the top object.- Specified by:
- rejectValuein interface- Errors
- Parameters:
- field- the field name (may be- nullor empty String)
- errorCode- error code, interpretable as a message key
- See Also:
 
- 
rejectValueDescription copied from interface:ErrorsRegister a field error for the specified field of the current object (respecting the current nested path, if any), using the given error description.The field name may be nullor empty String to indicate the current object itself rather than a field of it. This may result in a corresponding field error within the nested object graph or a global error if the current object is the top object.- Specified by:
- rejectValuein interface- Errors
- Parameters:
- field- the field name (may be- nullor empty String)
- errorCode- error code, interpretable as a message key
- defaultMessage- fallback default message
- See Also:
 
- 
hasErrorspublic boolean hasErrors()Description copied from interface:ErrorsDetermine if there were any errors.
- 
getErrorCountpublic int getErrorCount()Description copied from interface:ErrorsDetermine the total number of errors.- Specified by:
- getErrorCountin interface- Errors
- See Also:
 
- 
getAllErrorsDescription copied from interface:ErrorsGet all errors, both global and field ones.- Specified by:
- getAllErrorsin interface- Errors
- Returns:
- a list of ObjectError/FieldErrorinstances
- See Also:
 
- 
hasGlobalErrorspublic boolean hasGlobalErrors()Description copied from interface:ErrorsDetermine if there were any global errors.- Specified by:
- hasGlobalErrorsin interface- Errors
- See Also:
 
- 
getGlobalErrorCountpublic int getGlobalErrorCount()Description copied from interface:ErrorsDetermine the number of global errors.- Specified by:
- getGlobalErrorCountin interface- Errors
- See Also:
 
- 
getGlobalErrorDescription copied from interface:ErrorsGet the first global error, if any.- Specified by:
- getGlobalErrorin interface- Errors
- Returns:
- the global error, or null
- See Also:
 
- 
hasFieldErrorspublic boolean hasFieldErrors()Description copied from interface:ErrorsDetermine if there were any errors associated with a field.- Specified by:
- hasFieldErrorsin interface- Errors
- See Also:
 
- 
getFieldErrorCountpublic int getFieldErrorCount()Description copied from interface:ErrorsDetermine the number of errors associated with a field.- Specified by:
- getFieldErrorCountin interface- Errors
- See Also:
 
- 
getFieldErrorDescription copied from interface:ErrorsGet the first error associated with a field, if any.- Specified by:
- getFieldErrorin interface- Errors
- Returns:
- the field-specific error, or null
- See Also:
 
- 
hasFieldErrorsDescription copied from interface:ErrorsDetermine if there were any errors associated with the given field.- Specified by:
- hasFieldErrorsin interface- Errors
- Parameters:
- field- the field name
- See Also:
 
- 
getFieldErrorCountDescription copied from interface:ErrorsDetermine the number of errors associated with the given field.- Specified by:
- getFieldErrorCountin interface- Errors
- Parameters:
- field- the field name
- See Also:
 
- 
getFieldErrorsDescription copied from interface:ErrorsGet all errors associated with the given field.Implementations may support not only full field names like "address.street" but also pattern matches like "address.*". - Specified by:
- getFieldErrorsin interface- Errors
- Parameters:
- field- the field name
- Returns:
- a List of FieldErrorinstances
- See Also:
 
- 
getFieldErrorDescription copied from interface:ErrorsGet the first error associated with the given field, if any.- Specified by:
- getFieldErrorin interface- Errors
- Parameters:
- field- the field name
- Returns:
- the field-specific error, or null
- See Also:
 
- 
getFieldTypeDescription copied from interface:ErrorsDetermine the type of the given field, as far as possible.Implementations should be able to determine the type even when the field value is null, for example from some associated descriptor.- Specified by:
- getFieldTypein interface- Errors
- Parameters:
- field- the field name
- Returns:
- the type of the field, or nullif not determinable
- See Also:
 
- 
isMatchingFieldErrorCheck whether the given FieldError matches the given field.- Parameters:
- field- the field that we are looking up FieldErrors for
- fieldError- the candidate FieldError
- Returns:
- whether the FieldError matches the given field
 
- 
toString
 
-