MessageCodesResolver class abstract interface

The rule that turns an error code and a field into the list of message codes an error carries.

The codes decide which keys of messages.properties can give the message of an error. DefaultMessageCodesResolver is Spring's scheme (NotBlank.signup.name, NotBlank.name, ..., NotBlank) and almost every application keeps it. Implement this interface only to use other keys, for example to match an existing translation file, and pass it to DataBinder or a binding result.

// Upper-case codes: `NOTBLANK.name` in the message file.
class UpperCodes implements MessageCodesResolver {
  @override
  List<String> resolveMessageCodes(String errorCode, String objectName) =>
      [errorCode.toUpperCase()];

  @override
  List<String> resolveFieldMessageCodes(
    String errorCode,
    String objectName,
    String field,
    Type? fieldType,
  ) => ['${errorCode.toUpperCase()}.$field'];
}

DataBinder(form, messageCodesResolver: UpperCodes());

Spring (Java):

class UpperCodes implements MessageCodesResolver {
  public String[] resolveMessageCodes(String code, String objectName) {
    return new String[] {code.toUpperCase()};
  }

  public String[] resolveMessageCodes(
      String code, String objectName, String field, Class<?> type) {
    return new String[] {code.toUpperCase() + "." + field};
  }
}

binder.setMessageCodesResolver(new UpperCodes());

Properties

hashCode → int
The hash code for this object.
no setterinherited
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.
resolveMessageCodes(String errorCode, String objectName) → List<String>
The codes of an error of the whole object objectName with errorCode, most specific first.
toString() → String
A string representation of this object.
inherited

Operators

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