Top Description Fields Constructors Methods
org.springframework.validation

public abstract Class AbstractErrors

extends Object
implements Errors, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.springframework.validation.Errors
Known Direct Subclasses
org.springframework.validation.AbstractBindingResult
Annotations
@SuppressWarnings:serial
Imports
java.io.Serializable, java.util.ArrayDeque, .ArrayList, .Collections, .Deque, .List, .NoSuchElementException, org.springframework.lang.Nullable, org.springframework.util.StringUtils

Abstract implementation of the Errors interface. Provides nested path handling but does not define concrete management of ObjectErrors and FieldErrors.
Authors
Juergen Hoeller, Rossen Stoyanchev
Since
2.5.3
See Also
AbstractBindingResult

Field Summary

Modifier and TypeField and Description
private String
private final Deque<String>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected String

Returns:

the canonical field name
canonicalFieldName
(String
the original field name
field
)

Determine the canonical field name for the given field.

protected void
doSetNestedPath(String nestedPath)

Actually set the nested path.

protected String
fixedField(String field)

Transform the given field into its full path, regarding the nested path of this instance.

public List<FieldError>
getFieldErrors(String
the field name
field
)

Overrides default org.springframework.validation.Errors.getFieldErrors.

Get all errors associated with the given field.
public String
getNestedPath()

Overrides default org.springframework.validation.Errors.getNestedPath.

Return the current nested path of this Errors object.
protected boolean

Returns:

whether the FieldError matches the given field
isMatchingFieldError
(String
the field that we are looking up FieldErrors for
field
,
FieldError
the candidate FieldError
fieldError
)

Check whether the given FieldError matches the given field.

public void
popNestedPath()

Overrides default org.springframework.validation.Errors.popNestedPath.

Pop the former nested path from the nested path stack.
public void
pushNestedPath(String
the sub path to push onto the nested path stack
subPath
)

Overrides default org.springframework.validation.Errors.pushNestedPath.

Push the given sub path onto the nested path stack.
public void
setNestedPath(String
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.
nestedPath
)

Overrides default org.springframework.validation.Errors.setNestedPath.

Allow context to be changed so that standard validators can validate subtrees.
public String
toString()

Overrides java.lang.Object.toString.

Implements org.springframework.validation.Errors.toString.

Return a summary of the recorded errors, e.g. for inclusion in an exception message.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

nestedPathback to summary
private String nestedPath
nestedPathStackback to summary
private final Deque<String> nestedPathStack

Constructor Detail

AbstractErrorsback to summary
public AbstractErrors()

Method Detail

canonicalFieldNameback to summary
protected String canonicalFieldName(String field)

Determine the canonical field name for the given field.

The default implementation simply returns the field name as-is.

Parameters
field:String

the original field name

Returns:String

the canonical field name

doSetNestedPathback to summary
protected void doSetNestedPath(String nestedPath)

Actually set the nested path. Delegated to by setNestedPath and pushNestedPath.

fixedFieldback to summary
protected String fixedField(String field)

Transform the given field into its full path, regarding the nested path of this instance.

getFieldErrorsback to summary
public List<FieldError> getFieldErrors(String field)

Overrides default org.springframework.validation.Errors.getFieldErrors.

Doc from org.springframework.validation.Errors.getFieldErrors.

Get all errors associated with the given field.

Implementations may support not only full field names like "address.street" but also pattern matches like "address.*".

Parameters
field:String

the field name

Returns:List<FieldError>

a List of FieldError instances

Annotations
@Override
getNestedPathback to summary
public String getNestedPath()

Overrides default org.springframework.validation.Errors.getNestedPath.

Doc from org.springframework.validation.Errors.getNestedPath.

Return the current nested path of this Errors object.

Returns a nested path with a dot, i.e. "address.", for easy building of concatenated paths. Default is an empty String.

Annotations
@Override
isMatchingFieldErrorback to summary
protected boolean isMatchingFieldError(String field, FieldError fieldError)

Check whether the given FieldError matches the given field.

Parameters
field:String

the field that we are looking up FieldErrors for

fieldError:FieldError

the candidate FieldError

Returns:boolean

whether the FieldError matches the given field

popNestedPathback to summary
public void popNestedPath() throws IllegalStateException

Overrides default org.springframework.validation.Errors.popNestedPath.

Doc from org.springframework.validation.Errors.popNestedPath.

Pop the former nested path from the nested path stack.

Annotations
@Override
Exceptions
IllegalStateException:
if there is no former nested path on the stack
pushNestedPathback to summary
public void pushNestedPath(String subPath)

Overrides default org.springframework.validation.Errors.pushNestedPath.

Doc from org.springframework.validation.Errors.pushNestedPath.

Push the given sub path onto the nested path stack.

A popNestedPath() call will reset the original nested path before the corresponding pushNestedPath(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.

The default implementation throws UnsupportedOperationException since not all Errors implementations support nested paths.

Parameters
subPath:String

the sub path to push onto the nested path stack

Annotations
@Override
setNestedPathback to summary
public void setNestedPath(String nestedPath)

Overrides default org.springframework.validation.Errors.setNestedPath.

Doc from org.springframework.validation.Errors.setNestedPath.

Allow 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.

The default implementation throws UnsupportedOperationException since not all Errors implementations support nested paths.

Parameters
nestedPath:String

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.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements org.springframework.validation.Errors.toString.

Doc from org.springframework.validation.Errors.toString.

Return a summary of the recorded errors, e.g. for inclusion in an exception message.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override