public interface BindingResult extends Errors
interface
for error registration capabilities,
allowing for a Validator
to be applied, and adds
binding-specific analysis and model building.
Serves as result holder for a DataBinder
, obtained via
the DataBinder.getBindingResult()
method. BindingResult
implementations can also be used directly, for example to invoke
a Validator
on it (e.g. as part of a unit test).
DataBinder
,
Errors
,
Validator
,
BeanPropertyBindingResult
,
DirectFieldBindingResult
,
MapBindingResult
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MODEL_KEY_PREFIX
Prefix for the name of the BindingResult instance in a model,
followed by the object name.
|
NESTED_PATH_SEPARATOR
Modifier and Type | Method and Description |
---|---|
void |
addError(ObjectError error)
Add a custom
ObjectError or FieldError to the errors list. |
java.beans.PropertyEditor |
findEditor(java.lang.String field,
java.lang.Class<?> valueType)
Find a custom property editor for the given type and property.
|
java.util.Map<java.lang.String,java.lang.Object> |
getModel()
Return a model Map for the obtained state, exposing a BindingResult
instance as '
MODEL_KEY_PREFIX + objectName'
and the object itself as 'objectName'. |
PropertyEditorRegistry |
getPropertyEditorRegistry()
Return the underlying PropertyEditorRegistry.
|
java.lang.Object |
getRawFieldValue(java.lang.String field)
Extract the raw field value for the given field.
|
java.lang.String[] |
getSuppressedFields()
Return the list of fields that were suppressed during the bind process.
|
java.lang.Object |
getTarget()
Return the wrapped target object, which may be a bean, an object with
public fields, a Map - depending on the concrete binding strategy.
|
void |
recordSuppressedField(java.lang.String field)
Mark the specified disallowed field as suppressed.
|
java.lang.String[] |
resolveMessageCodes(java.lang.String errorCode)
Resolve the given error code into message codes.
|
java.lang.String[] |
resolveMessageCodes(java.lang.String errorCode,
java.lang.String field)
Resolve the given error code into message codes for the given field.
|
addAllErrors, getAllErrors, getErrorCount, getFieldError, getFieldError, getFieldErrorCount, getFieldErrorCount, getFieldErrors, getFieldErrors, getFieldType, getFieldValue, getGlobalError, getGlobalErrorCount, getGlobalErrors, getNestedPath, getObjectName, hasErrors, hasFieldErrors, hasFieldErrors, hasGlobalErrors, popNestedPath, pushNestedPath, reject, reject, reject, rejectValue, rejectValue, rejectValue, setNestedPath
static final java.lang.String MODEL_KEY_PREFIX
@Nullable java.lang.Object getTarget()
java.util.Map<java.lang.String,java.lang.Object> getModel()
MODEL_KEY_PREFIX
+ objectName'
and the object itself as 'objectName'.
Note that the Map is constructed every time you're calling this method. Adding things to the map and then re-calling this method will not work.
The attributes in the model Map returned by this method are usually
included in the ModelAndView
for a form view that uses Spring's bind
tag in a JSP,
which needs access to the BindingResult instance. Spring's pre-built
form controllers will do this for you when rendering a form view.
When building the ModelAndView instance yourself, you need to include
the attributes from the model Map returned by this method.
Errors.getObjectName()
,
MODEL_KEY_PREFIX
,
ModelAndView
,
BindTag
@Nullable java.lang.Object getRawFieldValue(java.lang.String field)
field
- the field to checknull
if not known@Nullable java.beans.PropertyEditor findEditor(@Nullable java.lang.String field, @Nullable java.lang.Class<?> valueType)
field
- the path of the property (name or nested path), or
null
if looking for an editor for all properties of the given typevalueType
- the type of the property (can be null
if a property
is given but should be specified in any case for consistency checking)null
if none@Nullable PropertyEditorRegistry getPropertyEditorRegistry()
null
if none
available for this BindingResultvoid addError(ObjectError error)
ObjectError
or FieldError
to the errors list.
Intended to be used by cooperating strategies such as BindingErrorProcessor
.
ObjectError
,
FieldError
,
BindingErrorProcessor
java.lang.String[] resolveMessageCodes(java.lang.String errorCode)
Calls the configured MessageCodesResolver
with appropriate parameters.
errorCode
- the error code to resolve into message codesjava.lang.String[] resolveMessageCodes(java.lang.String errorCode, java.lang.String field)
Calls the configured MessageCodesResolver
with appropriate parameters.
errorCode
- the error code to resolve into message codesfield
- the field to resolve message codes forvoid recordSuppressedField(java.lang.String field)
The data binder invokes this for each field value that was detected to target a disallowed field.
java.lang.String[] getSuppressedFields()
Can be used to determine whether any field values were targeting disallowed fields.