001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.validation;
018
019import org.springframework.beans.PropertyAccessException;
020
021/**
022 * Strategy for processing {@code DataBinder}'s missing field errors,
023 * and for translating a {@code PropertyAccessException} to a
024 * {@code FieldError}.
025 *
026 * <p>The error processor is pluggable so you can treat errors differently
027 * if you want to. A default implementation is provided for typical needs.
028 *
029 * <p>Note: As of Spring 2.0, this interface operates on a given BindingResult,
030 * to be compatible with any binding strategy (bean property, direct field access, etc).
031 * It can still receive a BindException as argument (since a BindException implements
032 * the BindingResult interface as well) but no longer operates on it directly.
033 *
034 * @author Alef Arendsen
035 * @author Juergen Hoeller
036 * @since 1.2
037 * @see DataBinder#setBindingErrorProcessor
038 * @see DefaultBindingErrorProcessor
039 * @see BindingResult
040 * @see BindException
041 */
042public interface BindingErrorProcessor {
043
044        /**
045         * Apply the missing field error to the given BindException.
046         * <p>Usually, a field error is created for a missing required field.
047         * @param missingField the field that was missing during binding
048         * @param bindingResult the errors object to add the error(s) to.
049         * You can add more than just one error or maybe even ignore it.
050         * The {@code BindingResult} object features convenience utils such as
051         * a {@code resolveMessageCodes} method to resolve an error code.
052         * @see BeanPropertyBindingResult#addError
053         * @see BeanPropertyBindingResult#resolveMessageCodes
054         */
055        void processMissingFieldError(String missingField, BindingResult bindingResult);
056
057        /**
058         * Translate the given {@code PropertyAccessException} to an appropriate
059         * error registered on the given {@code Errors} instance.
060         * <p>Note that two error types are available: {@code FieldError} and
061         * {@code ObjectError}. Usually, field errors are created, but in certain
062         * situations one might want to create a global {@code ObjectError} instead.
063         * @param ex the {@code PropertyAccessException} to translate
064         * @param bindingResult the errors object to add the error(s) to.
065         * You can add more than just one error or maybe even ignore it.
066         * The {@code BindingResult} object features convenience utils such as
067         * a {@code resolveMessageCodes} method to resolve an error code.
068         * @see Errors
069         * @see FieldError
070         * @see ObjectError
071         * @see MessageCodesResolver
072         * @see BeanPropertyBindingResult#addError
073         * @see BeanPropertyBindingResult#resolveMessageCodes
074         */
075        void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult);
076
077}