DefaultMessageCodesResolver class final

The standard message codes of errors, the ones every binding result and validator uses unless told otherwise.

You do not call it; you need its scheme to name the keys of messages.properties. An error carries several codes, from specific to general, and the first key the message file defines wins. So NotBlank=must not be empty covers every @NotBlank(), while NotBlank.signup.name=Please enter your name covers one field of one object.

For code NotBlank, object user and field orders[0].sku of type String, the codes are: NotBlank.user.orders[0].sku, NotBlank.user.orders.sku, NotBlank.orders[0].sku, NotBlank.orders.sku, NotBlank.sku, NotBlank.String, NotBlank. Indexes and keys are removed one at a time from the last (a[0][1].b also gives a[0].b and a.b), and the last path segment gets a code of its own (NotBlank.city for address.city), exactly as in Spring. The type is the Dart type name (String, not java.lang.String). An error of the whole object gets NotBlank.user and NotBlank.

Create one with a prefix or postfixFormat to change the keys, and pass it to DataBinder(messageCodesResolver: ...).

// All validation keys under `validation.` in the message file.
const resolver = DefaultMessageCodesResolver(prefix: 'validation.');
resolver.resolveFieldMessageCodes('NotBlank', 'user', 'name', String);
// [validation.NotBlank.user.name, validation.NotBlank.name,
//  validation.NotBlank.String, validation.NotBlank]

Spring (Java):

DefaultMessageCodesResolver resolver = new DefaultMessageCodesResolver();
resolver.setPrefix("validation.");
resolver.resolveMessageCodes("NotBlank", "user", "name", String.class);
Implemented types

Constructors

DefaultMessageCodesResolver({String prefix = '', bool postfixFormat = false})
A resolver that puts prefix before every code, and the error code last when postfixFormat is true. The defaults give Spring's codes.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
postfixFormat → bool
Whether the error code comes last (user.name.NotBlank) instead of first (NotBlank.user.name); false by default. Spring's POSTFIX_ERROR_CODE format.
final
prefix → String
Text put before every code, such as validation.; empty by default.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolveFieldMessageCodes(String errorCode, String objectName, String field, Type? fieldType) → List<String>
The codes of an error of field of objectName with errorCode, most specific first. fieldType is the declared type of the field, null when unknown.
override
resolveMessageCodes(String errorCode, String objectName) → List<String>
The codes of an error of the whole object objectName with errorCode, most specific first.
override
toString() → String
A string representation of this object.
inherited

Operators

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