Class SimpleErrors
- All Implemented Interfaces:
- Serializable,- Errors
Errors interface, managing global
 errors and field errors for a top-level target object. Flexibly retrieves
 field values through bean property getter methods, and automatically
 falls back to raw field access if necessary.
 Note that this Errors implementation comes without support for
 nested paths. It is exclusively designed for the validation of individual
 top-level objects, not aggregating errors from multiple sources.
 If this is insufficient for your purposes, use a binding-capable
 Errors implementation such as BeanPropertyBindingResult.
- Since:
- 6.1
- Author:
- Juergen Hoeller
- See Also:
- 
Field SummaryFields inherited from interface org.springframework.validation.ErrorsNESTED_PATH_SEPARATOR
- 
Constructor SummaryConstructorsConstructorDescriptionSimpleErrors(Object target) Create a newSimpleErrorsholder for the given target, using the simple name of the target class as the object name.SimpleErrors(Object target, String objectName) Create a newSimpleErrorsholder for the given target.
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddAllErrors(Errors errors) Add all errors from the givenErrorsinstance to thisErrorsinstance.booleanGet all errors associated with a field.Class<?>getFieldType(String field) Determine the type of the given field, as far as possible.getFieldValue(String field) Return the current value of the given field, either the current bean property value or a rejected update from the last binding.Get all global errors.Return the name of the bound root object.inthashCode()voidRegister a global error for the entire target object, using the given error description.voidrejectValue(String field, String errorCode, Object[] errorArgs, 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.toString()Return a summary of the recorded errors, e.g.Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.validation.ErrorsfailOnError, getAllErrors, getErrorCount, getFieldError, getFieldError, getFieldErrorCount, getFieldErrorCount, getFieldErrors, getGlobalError, getGlobalErrorCount, getNestedPath, hasErrors, hasFieldErrors, hasFieldErrors, hasGlobalErrors, popNestedPath, pushNestedPath, reject, reject, rejectValue, rejectValue, setNestedPath
- 
Constructor Details- 
SimpleErrorsCreate a newSimpleErrorsholder for the given target, using the simple name of the target class as the object name.- Parameters:
- target- the target to wrap
 
- 
SimpleErrorsCreate a newSimpleErrorsholder for the given target.- Parameters:
- target- the target to wrap
- objectName- the name of the target object for error reporting
 
 
- 
- 
Method Details- 
getObjectNameDescription copied from interface:ErrorsReturn the name of the bound root object.- Specified by:
- getObjectNamein interface- Errors
 
- 
rejectDescription copied from interface:ErrorsRegister a global error for the entire target object, using the given error description.
- 
rejectValuepublic void rejectValue(@Nullable String field, String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) Description 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
- errorArgs- error arguments, for argument binding via MessageFormat (can be- null)
- defaultMessage- fallback default message
- See Also:
 
- 
addAllErrorsDescription copied from interface:ErrorsAdd all errors from the givenErrorsinstance to thisErrorsinstance.This is a convenience method to avoid repeated reject(..)calls for merging anErrorsinstance into anotherErrorsinstance.Note that the passed-in Errorsinstance is supposed to refer to the same target object, or at least contain compatible errors that apply to the target object of thisErrorsinstance.The default implementation throws UnsupportedOperationExceptionsince not allErrorsimplementations support#addAllErrors.- Specified by:
- addAllErrorsin interface- Errors
- Parameters:
- errors- the- Errorsinstance to merge in
- See Also:
 
- 
getGlobalErrorsDescription copied from interface:ErrorsGet all global errors.- Specified by:
- getGlobalErrorsin interface- Errors
- Returns:
- a list of ObjectErrorinstances
- See Also:
 
- 
getFieldErrorsDescription copied from interface:ErrorsGet all errors associated with a field.- Specified by:
- getFieldErrorsin interface- Errors
- Returns:
- a List of FieldErrorinstances
- See Also:
 
- 
getFieldValueDescription copied from interface:ErrorsReturn the current value of the given field, either the current bean property value or a rejected update from the last binding.Allows for convenient access to user-specified field values, even if there were type mismatches. - Specified by:
- getFieldValuein interface- Errors
- Parameters:
- field- the field name
- Returns:
- the current value of the given field
- 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:
 
- 
equals
- 
hashCodepublic int hashCode()
- 
toStringDescription copied from interface:ErrorsReturn a summary of the recorded errors, e.g. for inclusion in an exception message.
 
-