Field names are typically properties of the target object (e.g. "name"
when binding to a customer object). Implementations may also support nested
fields in case of nested objects (e.g. "address.street"), in conjunction
with subtree navigation via setNestedPath: for example, an
AddressValidator may validate "address", not being aware that this
is a nested object of a top-level customer object.
Note
Errors objects are single-threaded.
Validator, ValidationUtils, SimpleErrors, BindingResult
| Modifier and Type | Field and Description |
|---|---|
| public static final String | NESTED_PATH_SEPARATOR
The separator between path elements in a nested path, for example in "customer.name" or "customer.address.street". |
| Modifier and Type | Method and Description |
|---|---|
| public default void | addAllErrors(Errors
the errors)Errors instance to merge inAdd all errors from the given |
| public default < the exception type to be thrown T extends Throwable> void | failOnError(Function<String, T>
a function mapping the message to the exception,
e.g. messageToException)IllegalArgumentException::new or IllegalStateException::newThrow the mapped exception with a message summarizing the recorded errors. |
| public default List | |
| public default int | |
| public default FieldError | Returns: the field-specific error, ornullGet the first error associated with a field, if any. |
| public default FieldError | Returns: the field-specific error, ornullthe field name field)Get the first error associated with the given field, if any. |
| public default int | |
| public default int | getFieldErrorCount(String
the field name field)Determine the number of errors associated with the given field. |
| public List | |
| public default List | Returns: a List ofFieldError instancesthe field name field)Get all errors associated with the given field. |
| public default Class | Returns: the type of the field, ornull if not determinablethe field name field)Determine the type of the given field, as far as possible. |
| public Object | Returns: the current value of the given fieldthe field name field)Return the current value of the given field, either the current bean property value or a rejected update from the last binding. |
| public default ObjectError | |
| public default int | |
| public List | |
| public default String | |
| public String | |
| public default boolean | |
| public default boolean | |
| public default boolean | hasFieldErrors(String
the field name field)Determine if there were any errors associated with the given field. |
| public default boolean | |
| public default void | |
| public default void | pushNestedPath(String
the sub path to push onto the nested path stack subPath)Push the given sub path onto the nested path stack. |
| public default void | |
| public default void | |
| public void | |
| public default void | rejectValue(String
the field name (may be field, String null or empty String)error code, interpretable as a message key 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. |
| public default void | rejectValue(String
the field name (may be field, String null or empty String)error code, interpretable as a message key errorCode, String fallback default message 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. |
| public void | rejectValue(String
the field name (may be field, String null or empty String)error code, interpretable as a message key errorCode, Object[] error arguments, for argument binding via MessageFormat
(can be errorArgs, String null)fallback default message 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. |
| public default void | setNestedPath(String
nested path within this object,
e.g. "address" (defaults to "", nestedPath)null is also acceptable).
Can end with a dot: both "address" and "address." are valid.Allow context to be changed so that standard validators can validate subtrees. |
| public String |
| NESTED_PATH_SEPARATOR | back to summary |
|---|---|
| public static final String NESTED_PATH_SEPARATOR The separator between path elements in a nested path, for example in "customer.name" or "customer.address.street". "." = same as the
| |
| addAllErrors | back to summary |
|---|---|
| public default void addAllErrors(Errors errors) Add all errors from the given This is a convenience method to avoid repeated Note that the passed-in The default implementation throws
| |
| failOnError | back to summary |
|---|---|
| public default <T extends Throwable> void failOnError(Function<String, T> messageToException) throws Function-:T Throw the mapped exception with a message summarizing the recorded errors.
| |
| getAllErrors | back to summary |
|---|---|
| public default List Get all errors, both global and field ones.
| |
| getErrorCount | back to summary |
|---|---|
| public default int getErrorCount() Determine the total number of errors.
| |
| getFieldError | back to summary |
|---|---|
| public default FieldError getFieldError() Get the first error associated with a field, if any.
| |
| getFieldError | back to summary |
|---|---|
| public default FieldError getFieldError(String field) Get the first error associated with the given field, if any.
| |
| getFieldErrorCount | back to summary |
|---|---|
| public default int getFieldErrorCount() Determine the number of errors associated with a field.
| |
| getFieldErrorCount | back to summary |
|---|---|
| public default int getFieldErrorCount(String field) Determine the number of errors associated with the given field.
| |
| getFieldErrors | back to summary |
|---|---|
| public List Get all errors associated with a field.
| |
| getFieldErrors | back to summary |
|---|---|
| public default List 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.*".
| |
| getFieldType | back to summary |
|---|---|
| public default Class Determine the type of the given field, as far as possible. Implementations should be able to determine the type even
when the field value is
| |
| getFieldValue | back to summary |
|---|---|
| public Object 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. Allows for convenient access to user-specified field values, even if there were type mismatches.
| |
| getGlobalError | back to summary |
|---|---|
| public default ObjectError getGlobalError() Get the first global error, if any.
| |
| getGlobalErrorCount | back to summary |
|---|---|
| public default int getGlobalErrorCount() Determine the number of global errors.
| |
| getGlobalErrors | back to summary |
|---|---|
| public List Get all global errors.
| |
| getNestedPath | back to summary |
|---|---|
| public default String getNestedPath() Return the current nested path of this Returns a nested path with a dot, i.e. "address.", for easy building of concatenated paths. Default is an empty String.
| |
| getObjectName | back to summary |
|---|---|
| public String getObjectName() Return the name of the bound root object. | |
| hasErrors | back to summary |
|---|---|
| public default boolean hasErrors() Determine if there were any errors.
| |
| hasFieldErrors | back to summary |
|---|---|
| public default boolean hasFieldErrors() Determine if there were any errors associated with a field.
| |
| hasFieldErrors | back to summary |
|---|---|
| public default boolean hasFieldErrors(String field) Determine if there were any errors associated with the given field.
| |
| hasGlobalErrors | back to summary |
|---|---|
| public default boolean hasGlobalErrors() Determine if there were any global errors.
| |
| popNestedPath | back to summary |
|---|---|
| public default void popNestedPath() throws IllegalStateException Pop the former nested path from the nested path stack.
| |
| pushNestedPath | back to summary |
|---|---|
| public default void pushNestedPath(String subPath) Push the given sub path onto the nested path stack. A 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
| |
| reject | back to summary |
|---|---|
| public default void reject(String errorCode) Register a global error for the entire target object, using the given error description.
| |
| reject | back to summary |
|---|---|
| public default void reject(String errorCode, String defaultMessage) Register a global error for the entire target object, using the given error description.
| |
| reject | back to summary |
|---|---|
| public void reject(String errorCode, Object[] errorArgs, String defaultMessage) Register a global error for the entire target object, using the given error description.
| |
| rejectValue | back to summary |
|---|---|
| public default void rejectValue(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. The field name may be
| |
| rejectValue | back to summary |
|---|---|
| public default void rejectValue(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. The field name may be
| |
| rejectValue | back to summary |
|---|---|
| public void rejectValue(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. The field name may be
| |
| setNestedPath | back to summary |
|---|---|
| public default void setNestedPath(String nestedPath) 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
| |
| toString | back to summary |
|---|---|
| public String toString() Return a summary of the recorded errors, e.g. for inclusion in an exception message.
| |