001: /*
002: * Copyright 2002-2006 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: * http://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:
017: package org.springframework.validation;
018:
019: import java.util.Map;
020:
021: import org.springframework.beans.PropertyEditorRegistry;
022:
023: /**
024: * General interface that represents binding results. Extends the
025: * {@link Errors interface} for error registration capabilities,
026: * allowing for a {@link Validator} to be applied, and adds
027: * binding-specific analysis and model building.
028: *
029: * <p>Serves as result holder for a {@link DataBinder}, obtained via
030: * the {@link DataBinder#getBindingResult()} method. BindingResult
031: * implementations can also be used directly, for example to invoke
032: * a {@link Validator} on it (e.g. as part of a unit test).
033: *
034: * @author Juergen Hoeller
035: * @since 2.0
036: * @see DataBinder
037: * @see Errors
038: * @see Validator
039: * @see BeanPropertyBindingResult
040: * @see DirectFieldBindingResult
041: * @see MapBindingResult
042: */
043: public interface BindingResult extends Errors {
044:
045: /**
046: * Prefix for the name of the BindingResult instance in a model,
047: * followed by the object name.
048: */
049: String MODEL_KEY_PREFIX = BindingResult.class.getName() + ".";
050:
051: /**
052: * Return the wrapped target object, which may be a bean, an object with
053: * public fields, a Map - depending on the concrete binding strategy.
054: */
055: Object getTarget();
056:
057: /**
058: * Return a model Map for the obtained state, exposing a BindingResult
059: * instance as '{@link #MODEL_KEY_PREFIX MODEL_KEY_PREFIX} + objectName'
060: * and the object itself as 'objectName'.
061: * <p>Note that the Map is constructed every time you're calling this method.
062: * Adding things to the map and then re-calling this method will not work.
063: * <p>The attributes in the model Map returned by this method are usually
064: * included in the {@link org.springframework.web.servlet.ModelAndView}
065: * for a form view that uses Spring's <code>bind</code> tag in a JSP,
066: * which needs access to the BindingResult instance. Spring's pre-built
067: * form controllers will do this for you when rendering a form view.
068: * When building the ModelAndView instance yourself, you need to include
069: * the attributes from the model Map returned by this method.
070: * @see #getObjectName()
071: * @see #MODEL_KEY_PREFIX
072: * @see org.springframework.web.servlet.ModelAndView
073: * @see org.springframework.web.servlet.tags.BindTag
074: * @see org.springframework.web.servlet.mvc.SimpleFormController
075: */
076: Map getModel();
077:
078: /**
079: * Return the underlying PropertyEditorRegistry.
080: * @throws UnsupportedOperationException if the BindingResult
081: * does not support a PropertyEditorRegistry
082: */
083: PropertyEditorRegistry getPropertyEditorRegistry();
084:
085: /**
086: * Mark the specified disallowed field as suppressed.
087: * <p>The data binder invokes this for each field value that was
088: * detected to target a disallowed field.
089: * @see DataBinder#setAllowedFields
090: */
091: void recordSuppressedField(String fieldName);
092:
093: /**
094: * Return the list of fields that were suppressed during the bind process.
095: * <p>Can be used to determine whether any field values were targeting
096: * disallowed fields.
097: * @see DataBinder#setAllowedFields
098: */
099: String[] getSuppressedFields();
100:
101: /**
102: * Add a custom {@link ObjectError} or {@link FieldError} to the errors list.
103: * <p>Intended to be used by cooperating strategies such as {@link BindingErrorProcessor}.
104: * @see ObjectError
105: * @see FieldError
106: * @see BindingErrorProcessor
107: */
108: void addError(ObjectError error);
109:
110: /**
111: * Resolve the given error code into message codes for the given field.
112: * <p>Calls the configured {@link MessageCodesResolver} with appropriate parameters.
113: * @param errorCode the error code to resolve into message codes
114: * @param field the field to resolve message codes for
115: * @return the resolved message codes
116: */
117: String[] resolveMessageCodes(String errorCode, String field);
118:
119: }
|