MapBindingResult class
A BindingResult for values held in a map instead of an object.
Use it to check loose input with a hand-written Validator or the
ValidationUtils helpers, for example request parameters that were
never bound onto a class. Field names are the map keys; a field's type
is the runtime type of its current value.
// A required parameter, checked without a form class.
final errors = MapBindingResult({'email': ''}, 'request');
ValidationUtils.rejectIfEmpty(errors, 'email', 'required');
errors.hasFieldErrors('email'); // true
Spring (Java):
Map<String, Object> values = new HashMap<>(Map.of("email", ""));
Errors errors = new MapBindingResult(values, "request");
ValidationUtils.rejectIfEmpty(errors, "email", "required");
errors.hasFieldErrors("email");
- Inheritance
-
- Object
- AbstractBindingResult
- MapBindingResult
Constructors
-
MapBindingResult(Map<
String, Object?> target, String objectName, {MessageCodesResolver messageCodesResolver = const DefaultMessageCodesResolver()}) -
An empty result for the map
target, namedobjectNamein message codes.
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;
nullwhen 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.
finalinherited
-
model
→ Map<
String, Object?> -
A map for a view model: the target under objectName and this result
under
BindingResult.<objectName>.no setterinherited - 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.finalinherited - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
target
→ Map<
String, Object?> -
The object being bound or validated;
nullwhen constructor binding could not create it.final
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
errorbuilt 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.inherited -
fieldError(
[String? field]) → FieldError? -
The first error of
field(or of any field when omitted);nullwhen there is none.inherited -
fieldErrors(
[String? field]) → List< FieldError> -
The field errors in the order they were recorded: all when
fieldis omitted, else those offield(relative to nestedPath); a trailing*matches every field under a path (address.*).inherited -
getFieldType(
String field) → Type? -
The declared type of
field, for the type code (NotBlank.String);nullwhen unknown, and that code is left out.override -
getFieldValue(
String field) → Object? -
The value to show for
fieldin 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
fieldon the target, ignoring errors (unlike getFieldValue, which prefers the rejected value).override -
hasFieldErrors(
[String? field]) → bool -
Whether a field has errors: any field when
fieldis 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 = const [], String? defaultMessage, Type? fieldType}) → void -
Records a binding failure of
field: the inputrejectedValuecould not be stored, for example text for a number.inherited -
reject(
String errorCode, {List< Object?> args = const [], String? defaultMessage, bool renderDefaultMessage = true}) → void -
Records an error of the whole object with
errorCode, such aspasswordsMismatch.inherited -
rejectValue(
String field, String errorCode, {List< Object?> args = const [], String? defaultMessage, bool renderDefaultMessage = true}) → void -
Records an error of
field(relative to nestedPath) witherrorCode, such asrequired; the field's current value becomes the rejected value.inherited -
resolveMessageCodes(
String errorCode, [String? field]) → List< String> -
The message codes an error with
errorCodewould get: offield(relative to the nested path) when given, else of the whole object.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited