BindingResult class abstract interface

The outcome of binding input onto an object and validating it: the Errors together with the object they are about.

This is the object applications read after validation: from DataBinder.bindingResult, from a MethodArgumentNotValidException in a web exception handler, or from a BeanPropertyBindingResult they passed to a validator. Besides the errors it gives the target, reads field values, and lets framework code add prepared errors.

// Log each field error after binding a form.
final result = binder.bindingResult;
if (result.hasErrors) {
  for (final error in result.fieldErrors()) {
    log.warning('${error.field}: ${error.defaultMessage}');
  }
}

Spring (Java):

BindingResult result = binder.getBindingResult();
if (result.hasErrors()) {
  for (FieldError error : result.getFieldErrors()) {
    log.warn(error.getField() + ": "
        + error.getDefaultMessage());
  }
}
Implemented types
Implementers

Properties

allErrors → List<ObjectError>
Every error, of fields and of the object, in the order they were recorded.
no setterinherited
errorCount → int
The number of errors, of fields and of the object.
no setterinherited
globalError → ObjectError?
The first error of the whole object; null when there is none.
no setterinherited
globalErrors → List<ObjectError>
The errors of the whole object, the ones that are not FieldErrors, in the order they were recorded.
no setterinherited
hasErrors → bool
Whether any error, of a field or of the object, was recorded.
no setterinherited
hasGlobalErrors → bool
Whether an error of the whole object (not of a field) was recorded.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
messageCodesResolver → MessageCodesResolver
The rule that builds the message codes of new errors; DefaultMessageCodesResolver unless one was given.
no setter
model → Map<String, Object?>
A map for a view model: the target under objectName and this result under BindingResult.<objectName>.
no setter
nestedPath ↔ String
The path put before the field names given to rejectValue and the field queries, such as address.; empty at the top level.
getter/setter pairinherited
objectName → String
Name of the validated object, such as signup; part of every message code.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
target → Object?
The object being bound or validated; null when constructor binding could not create it.
no setter

Methods

addAllErrors(Errors errors) → void
Copies every error of errors, for example from a validator run on a separate result. Throws an ArgumentError when its objectName differs.
inherited
addError(ObjectError error) → void
Records an error built elsewhere, codes included; the validator uses it to keep a rejected value it chose. Throws an ArgumentError when the error's object name differs from objectName.
fieldError([String? field]) → FieldError?
The first error of field (or of any field when omitted); null when there is none.
inherited
fieldErrors([String? field]) → List<FieldError>
The field errors in the order they were recorded: all when field is omitted, else those of field (relative to nestedPath); a trailing * matches every field under a path (address.*).
inherited
getFieldValue(String field) → Object?
The value to show for field in a form: the rejected value of its first error when it has one, else its current value.
inherited
getRawFieldValue(String field) → Object?
The current value of field on the target, ignoring errors (unlike getFieldValue, which prefers the rejected value).
hasFieldErrors([String? field]) → bool
Whether a field has errors: any field when field is omitted, else that field (relative to nestedPath), or every field under a path that ends with * (address.*).
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
popNestedPath() → void
Goes back to the nested path saved by the last pushNestedPath; throws a StateError when none is saved.
inherited
pushNestedPath(String subPath) → void
Goes one level down: appends subPath (address, items[0]) to the nested path and saves the current one for popNestedPath.
inherited
recordFieldError(String field, String errorCode, Object? rejectedValue, {List<Object?> args, String? defaultMessage, Type? fieldType}) → void
Records a binding failure of field: the input rejectedValue could not be stored, for example text for a number.
reject(String errorCode, {List<Object?> args, String? defaultMessage, bool renderDefaultMessage}) → void
Records an error of the whole object with errorCode, such as passwordsMismatch.
inherited
rejectValue(String field, String errorCode, {List<Object?> args, String? defaultMessage, bool renderDefaultMessage}) → void
Records an error of field (relative to nestedPath) with errorCode, such as required; the field's current value becomes the rejected value.
inherited
resolveMessageCodes(String errorCode, [String? field]) → List<String>
The message codes an error with errorCode would get: of field (relative to the nested path) when given, else of the whole object.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

modelKeyPrefix → const String
The start of the key under which model holds a binding result: BindingResult.signup for the object signup. Spring's key starts with the full class name, org.springframework.validation..