org.springframework.validation

Interface BindingResult

    • Field Detail

      • MODEL_KEY_PREFIX

        static final java.lang.String MODEL_KEY_PREFIX
        Prefix for the name of the BindingResult instance in a model, followed by the object name.
    • Method Detail

      • getTarget

        @Nullable
        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.
      • getModel

        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'.

        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.

        See Also:
        Errors.getObjectName(), MODEL_KEY_PREFIX, ModelAndView, BindTag
      • getRawFieldValue

        @Nullable
        java.lang.Object getRawFieldValue(java.lang.String field)
        Extract the raw field value for the given field. Typically used for comparison purposes.
        Parameters:
        field - the field to check
        Returns:
        the current value of the field in its raw form, or null if not known
      • findEditor

        @Nullable
        java.beans.PropertyEditor findEditor(@Nullable
                                                       java.lang.String field,
                                                       @Nullable
                                                       java.lang.Class<?> valueType)
        Find a custom property editor for the given type and property.
        Parameters:
        field - the path of the property (name or nested path), or null if looking for an editor for all properties of the given type
        valueType - the type of the property (can be null if a property is given but should be specified in any case for consistency checking)
        Returns:
        the registered editor, or null if none
      • getPropertyEditorRegistry

        @Nullable
        PropertyEditorRegistry getPropertyEditorRegistry()
        Return the underlying PropertyEditorRegistry.
        Returns:
        the PropertyEditorRegistry, or null if none available for this BindingResult
      • resolveMessageCodes

        java.lang.String[] resolveMessageCodes(java.lang.String errorCode)
        Resolve the given error code into message codes.

        Calls the configured MessageCodesResolver with appropriate parameters.

        Parameters:
        errorCode - the error code to resolve into message codes
        Returns:
        the resolved message codes
      • resolveMessageCodes

        java.lang.String[] resolveMessageCodes(java.lang.String errorCode,
                                               java.lang.String field)
        Resolve the given error code into message codes for the given field.

        Calls the configured MessageCodesResolver with appropriate parameters.

        Parameters:
        errorCode - the error code to resolve into message codes
        field - the field to resolve message codes for
        Returns:
        the resolved message codes
      • recordFieldValue

        default void recordFieldValue(java.lang.String field,
                                      java.lang.Class<?> type,
                                      @Nullable
                                      java.lang.Object value)
        Record the given value for the specified field.

        To be used when a target object cannot be constructed, making the original field values available through Errors.getFieldValue(java.lang.String). In case of a registered error, the rejected value will be exposed for each affected field.

        Parameters:
        field - the field to record the value for
        type - the type of the field
        value - the original value
        Since:
        5.0.4
      • recordSuppressedField

        default void recordSuppressedField(java.lang.String field)
        Mark the specified disallowed field as suppressed.

        The data binder invokes this for each field value that was detected to target a disallowed field.

        See Also:
        DataBinder.setAllowedFields(java.lang.String...)
      • getSuppressedFields

        default java.lang.String[] getSuppressedFields()
        Return the list of fields that were suppressed during the bind process.

        Can be used to determine whether any field values were targeting disallowed fields.

        See Also:
        DataBinder.setAllowedFields(java.lang.String...)