Stores and exposes information about data-binding and validation
errors for a specific object.
Field names can be properties of the target object (e.g. "name"
when binding to a customer object), or nested fields in case of
subobjects (e.g. "address.street"). Supports subtree navigation
via setNestedPath(String): for example, an
AddressValidator validates "address", not being aware
that this is a subobject of customer.
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.
Parameters:
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.
getNestedPath
java.lang.String 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.
pushNestedPath
void pushNestedPath(java.lang.String subPath)
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.
Parameters:
subPath - the sub path to push onto the nested path stack
Register 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 null or 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.
Parameters:
field - the field name (may be null or empty String)
errorCode - error code, interpretable as a message key
Register 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 null or 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.
Parameters:
field - the field name (may be null or empty String)
errorCode - error code, interpretable as a message key
Register 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 null or 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.
Parameters:
field - the field name (may be null or empty String)
errorCode - error code, interpretable as a message key
errorArgs - error arguments, for argument binding via MessageFormat
(can be null)
Add all errors from the given Errors instance to this
Errors instance.
This is a convenience method to avoid repeated reject(..)
calls for merging an Errors instance into another
Errors instance.
Note that the passed-in Errors instance is supposed
to refer to the same target object, or at least contain compatible errors
that apply to the target object of this Errors instance.