Top Description Fields Constructors Methods
org.springframework.validation.method

public Class ParameterErrors

extends ParameterValidationResult
implements Errors
Class Inheritance
All Implemented Interfaces
org.springframework.validation.Errors
Imports
java.util.List, org.springframework.core.MethodParameter, org.springframework.lang.Nullable, org.springframework.validation.Errors, .FieldError, .ObjectError

Extension of ParameterValidationResult created for Object method parameters or return values with nested errors on their properties.

The base class method getResolvableErrors() returns Errors#getAllErrors(), but this subclass provides access to the same as FieldErrors.

Author
Rossen Stoyanchev
Since
6.1

Field Summary

Modifier and TypeField and Description
private final Errors

Constructor Summary

AccessConstructor and Description
public
ParameterErrors(MethodParameter parameter, Object argument, Errors errors, Object container, Integer index, Object key)

Create a ParameterErrors.

Method Summary

Modifier and TypeMethod and Description
public void
addAllErrors(Errors
the Errors instance to merge in
errors
)

Overrides default org.springframework.validation.Errors.addAllErrors.

Add all errors from the given Errors instance to this Errors instance.

public List<ObjectError>
getAllErrors()

Overrides default org.springframework.validation.Errors.getAllErrors.

Get all errors, both global and field ones.

public int
getErrorCount()

Overrides default org.springframework.validation.Errors.getErrorCount.

Determine the total number of errors.

public FieldError
getFieldError()

Overrides default org.springframework.validation.Errors.getFieldError.

Get the first error associated with a field, if any.

public FieldError
getFieldError(String
the field name
field
)

Overrides default org.springframework.validation.Errors.getFieldError.

Get the first error associated with the given field, if any.

public int
getFieldErrorCount()

Overrides default org.springframework.validation.Errors.getFieldErrorCount.

Determine the number of errors associated with a field.

public int
getFieldErrorCount(String
the field name
field
)

Overrides default org.springframework.validation.Errors.getFieldErrorCount.

Determine the number of errors associated with the given field.

public List<FieldError>
getFieldErrors()

Implements org.springframework.validation.Errors.getFieldErrors.

Get all errors associated with a field.

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 Class<?>
getFieldType(String
the field name
field
)

Overrides default org.springframework.validation.Errors.getFieldType.

Determine the type of the given field, as far as possible.

public Object
getFieldValue(String
the field name
field
)

Implements org.springframework.validation.Errors.getFieldValue.

Return the current value of the given field, either the current bean property value or a rejected update from the last binding.

public ObjectError
getGlobalError()

Overrides default org.springframework.validation.Errors.getGlobalError.

Get the first global error, if any.

public int
getGlobalErrorCount()

Overrides default org.springframework.validation.Errors.getGlobalErrorCount.

Determine the number of global errors.

public List<ObjectError>
public String
getNestedPath()

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

Return the current nested path of this Errors object.

public String
getObjectName()

Implements org.springframework.validation.Errors.getObjectName.

Return the name of the bound root object.

public boolean
hasErrors()

Overrides default org.springframework.validation.Errors.hasErrors.

Determine if there were any errors.

public boolean
hasFieldErrors()

Overrides default org.springframework.validation.Errors.hasFieldErrors.

Determine if there were any errors associated with a field.

public boolean
hasFieldErrors(String
the field name
field
)

Overrides default org.springframework.validation.Errors.hasFieldErrors.

Determine if there were any errors associated with the given field.

public boolean
hasGlobalErrors()

Overrides default org.springframework.validation.Errors.hasGlobalErrors.

Determine if there were any global errors.

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
reject(String
error code, interpretable as a message key
errorCode
)

Overrides default org.springframework.validation.Errors.reject.

Register a global error for the entire target object, using the given error description.

public void
reject(String
error code, interpretable as a message key
errorCode
,
String
fallback default message
defaultMessage
)

Overrides default org.springframework.validation.Errors.reject.

Register a global error for the entire target object, using the given error description.

public void
reject(String
error code, interpretable as a message key
errorCode
,
Object[]
error arguments, for argument binding via MessageFormat (can be null)
errorArgs
,
String
fallback default message
defaultMessage
)

Implements org.springframework.validation.Errors.reject.

Register a global error for the entire target object, using the given error description.

public void
rejectValue(String
the field name (may be null or empty String)
field
,
String
error code, interpretable as a message key
errorCode
)

Overrides default org.springframework.validation.Errors.rejectValue.

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 null or empty String)
field
,
String
error code, interpretable as a message key
errorCode
,
String
fallback default message
defaultMessage
)

Overrides default org.springframework.validation.Errors.rejectValue.

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 null or empty String)
field
,
String
error code, interpretable as a message key
errorCode
,
Object[]
error arguments, for argument binding via MessageFormat (can be null)
errorArgs
,
String
fallback default message
defaultMessage
)

Implements org.springframework.validation.Errors.rejectValue.

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

Inherited from org.springframework.validation.method.ParameterValidationResult:
equalsgetArgumentgetContainergetContainerIndexgetContainerKeygetMethodParametergetResolvableErrorshashCodetoString

Field Detail

errorsback to summary
private final Errors errors

Constructor Detail

ParameterErrorsback to summary
public ParameterErrors(MethodParameter parameter, Object argument, Errors errors, Object container, Integer index, Object key)

Create a ParameterErrors.

Method Detail

addAllErrorsback to summary
public void addAllErrors(Errors errors)

Overrides default org.springframework.validation.Errors.addAllErrors.

Doc from org.springframework.validation.Errors.addAllErrors.

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.

The default implementation throws UnsupportedOperationException since not all Errors implementations support #addAllErrors.

Parameters
errors:Errors

the Errors instance to merge in

Annotations
@Override
getAllErrorsback to summary
public List<ObjectError> getAllErrors()

Overrides default org.springframework.validation.Errors.getAllErrors.

Doc from org.springframework.validation.Errors.getAllErrors.

Get all errors, both global and field ones.

Returns:List<ObjectError>

a list of ObjectError/FieldError instances

Annotations
@Override
getErrorCountback to summary
public int getErrorCount()

Overrides default org.springframework.validation.Errors.getErrorCount.

Doc from org.springframework.validation.Errors.getErrorCount.

Determine the total number of errors.

Annotations
@Override
getFieldErrorback to summary
public FieldError getFieldError()

Overrides default org.springframework.validation.Errors.getFieldError.

Doc from org.springframework.validation.Errors.getFieldError.

Get the first error associated with a field, if any.

Returns:FieldError

the field-specific error, or null

Annotations
@Override
getFieldErrorback to summary
public FieldError getFieldError(String field)

Overrides default org.springframework.validation.Errors.getFieldError.

Doc from org.springframework.validation.Errors.getFieldError.

Get the first error associated with the given field, if any.

Parameters
field:String

the field name

Returns:FieldError

the field-specific error, or null

Annotations
@Override
getFieldErrorCountback to summary
public int getFieldErrorCount()

Overrides default org.springframework.validation.Errors.getFieldErrorCount.

Doc from org.springframework.validation.Errors.getFieldErrorCount.

Determine the number of errors associated with a field.

Annotations
@Override
getFieldErrorCountback to summary
public int getFieldErrorCount(String field)

Overrides default org.springframework.validation.Errors.getFieldErrorCount.

Doc from org.springframework.validation.Errors.getFieldErrorCount.

Determine the number of errors associated with the given field.

Parameters
field:String

the field name

Annotations
@Override
getFieldErrorsback to summary
public List<FieldError> getFieldErrors()

Implements org.springframework.validation.Errors.getFieldErrors.

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

Get all errors associated with a field.

Returns:List<FieldError>

a List of FieldError instances

Annotations
@Override
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
getFieldTypeback to summary
public Class<?> getFieldType(String field)

Overrides default org.springframework.validation.Errors.getFieldType.

Doc from org.springframework.validation.Errors.getFieldType.

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 null, for example from some associated descriptor.

Parameters
field:String

the field name

Returns:Class<?>

the type of the field, or null if not determinable

Annotations
@Override
getFieldValueback to summary
public Object getFieldValue(String field)

Implements org.springframework.validation.Errors.getFieldValue.

Doc from org.springframework.validation.Errors.getFieldValue.

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.

Parameters
field:String

the field name

Returns:Object

the current value of the given field

Annotations
@Override
getGlobalErrorback to summary
public ObjectError getGlobalError()

Overrides default org.springframework.validation.Errors.getGlobalError.

Doc from org.springframework.validation.Errors.getGlobalError.

Get the first global error, if any.

Returns:ObjectError

the global error, or null

Annotations
@Override
getGlobalErrorCountback to summary
public int getGlobalErrorCount()

Overrides default org.springframework.validation.Errors.getGlobalErrorCount.

Doc from org.springframework.validation.Errors.getGlobalErrorCount.

Determine the number of global errors.

Annotations
@Override
getGlobalErrorsback to summary
public List<ObjectError> getGlobalErrors()

Implements org.springframework.validation.Errors.getGlobalErrors.

Doc from org.springframework.validation.Errors.getGlobalErrors.

Get all global errors.

Returns:List<ObjectError>

a list of ObjectError 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
getObjectNameback to summary
public String getObjectName()

Implements org.springframework.validation.Errors.getObjectName.

Doc from org.springframework.validation.Errors.getObjectName.

Return the name of the bound root object.

Annotations
@Override
hasErrorsback to summary
public boolean hasErrors()

Overrides default org.springframework.validation.Errors.hasErrors.

Doc from org.springframework.validation.Errors.hasErrors.

Determine if there were any errors.

Annotations
@Override
hasFieldErrorsback to summary
public boolean hasFieldErrors()

Overrides default org.springframework.validation.Errors.hasFieldErrors.

Doc from org.springframework.validation.Errors.hasFieldErrors.

Determine if there were any errors associated with a field.

Annotations
@Override
hasFieldErrorsback to summary
public boolean hasFieldErrors(String field)

Overrides default org.springframework.validation.Errors.hasFieldErrors.

Doc from org.springframework.validation.Errors.hasFieldErrors.

Determine if there were any errors associated with the given field.

Parameters
field:String

the field name

Annotations
@Override
hasGlobalErrorsback to summary
public boolean hasGlobalErrors()

Overrides default org.springframework.validation.Errors.hasGlobalErrors.

Doc from org.springframework.validation.Errors.hasGlobalErrors.

Determine if there were any global errors.

Annotations
@Override
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
rejectback to summary
public void reject(String errorCode)

Overrides default org.springframework.validation.Errors.reject.

Doc from org.springframework.validation.Errors.reject.

Register a global error for the entire target object, using the given error description.

Parameters
errorCode:String

error code, interpretable as a message key

Annotations
@Override
rejectback to summary
public void reject(String errorCode, String defaultMessage)

Overrides default org.springframework.validation.Errors.reject.

Doc from org.springframework.validation.Errors.reject.

Register a global error for the entire target object, using the given error description.

Parameters
errorCode:String

error code, interpretable as a message key

defaultMessage:String

fallback default message

Annotations
@Override
rejectback to summary
public void reject(String errorCode, Object[] errorArgs, String defaultMessage)

Implements org.springframework.validation.Errors.reject.

Doc from org.springframework.validation.Errors.reject.

Register a global error for the entire target object, using the given error description.

Parameters
errorCode:String

error code, interpretable as a message key

errorArgs:Object[]

error arguments, for argument binding via MessageFormat (can be null)

defaultMessage:String

fallback default message

Annotations
@Override
rejectValueback to summary
public void rejectValue(String field, String errorCode)

Overrides default org.springframework.validation.Errors.rejectValue.

Doc from org.springframework.validation.Errors.rejectValue.

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:String

the field name (may be null or empty String)

errorCode:String

error code, interpretable as a message key

Annotations
@Override
rejectValueback to summary
public void rejectValue(String field, String errorCode, String defaultMessage)

Overrides default org.springframework.validation.Errors.rejectValue.

Doc from org.springframework.validation.Errors.rejectValue.

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:String

the field name (may be null or empty String)

errorCode:String

error code, interpretable as a message key

defaultMessage:String

fallback default message

Annotations
@Override
rejectValueback to summary
public void rejectValue(String field, String errorCode, Object[] errorArgs, String defaultMessage)

Implements org.springframework.validation.Errors.rejectValue.

Doc from org.springframework.validation.Errors.rejectValue.

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:String

the field name (may be null or empty String)

errorCode:String

error code, interpretable as a message key

errorArgs:Object[]

error arguments, for argument binding via MessageFormat (can be null)

defaultMessage:String

fallback default message

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