@Override @Nullable public Object getRawFieldValue(String field) { return (getTarget() != null ? getActualFieldValue(fixedField(field)) : null); }
/** * This default implementation determines the type based on the actual * field value, if any. Subclasses should override this to determine * the type from a descriptor, even for {@code null} values. * @see #getActualFieldValue */ @Override @Nullable public Class<?> getFieldType(@Nullable String field) { if (getTarget() != null) { Object value = getActualFieldValue(fixedField(field)); if (value != null) { return value.getClass(); } } return this.fieldTypes.get(field); }
/** * Return a model Map for the obtained state, exposing an Errors * instance as '{@link #MODEL_KEY_PREFIX MODEL_KEY_PREFIX} + objectName' * and the object itself. * <p>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. * <p>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, * which needs access to the Errors instance. * @see #getObjectName * @see #MODEL_KEY_PREFIX */ @Override public Map<String, Object> getModel() { Map<String, Object> model = new LinkedHashMap<>(2); // Mapping from name to target object. model.put(getObjectName(), getTarget()); // Errors instance, even if no errors. model.put(MODEL_KEY_PREFIX + getObjectName(), this); return model; }
@Override @Nullable public Object getRawFieldValue(String field) { return (getTarget() != null ? getActualFieldValue(fixedField(field)) : null); }
/** * This default implementation determines the type based on the actual * field value, if any. Subclasses should override this to determine * the type from a descriptor, even for {@code null} values. * @see #getActualFieldValue */ @Override @Nullable public Class<?> getFieldType(@Nullable String field) { if (getTarget() != null) { Object value = getActualFieldValue(fixedField(field)); if (value != null) { return value.getClass(); } } return this.fieldTypes.get(field); }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof BindingResult)) { return false; } BindingResult otherResult = (BindingResult) other; return (getObjectName().equals(otherResult.getObjectName()) && ObjectUtils.nullSafeEquals(getTarget(), otherResult.getTarget()) && getAllErrors().equals(otherResult.getAllErrors())); }
/** * Return a model Map for the obtained state, exposing an Errors * instance as '{@link #MODEL_KEY_PREFIX MODEL_KEY_PREFIX} + objectName' * and the object itself. * <p>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. * <p>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, * which needs access to the Errors instance. * @see #getObjectName * @see #MODEL_KEY_PREFIX */ @Override public Map<String, Object> getModel() { Map<String, Object> model = new LinkedHashMap<>(2); // Mapping from name to target object. model.put(getObjectName(), getTarget()); // Errors instance, even if no errors. model.put(MODEL_KEY_PREFIX + getObjectName(), this); return model; }
@Override @Nullable public Object getFieldValue(String field) { FieldError fieldError = getFieldError(field); // Use rejected value in case of error, current field value otherwise. if (fieldError != null) { Object value = fieldError.getRejectedValue(); // Do not apply formatting on binding failures like type mismatches. return (fieldError.isBindingFailure() || getTarget() == null ? value : formatFieldValue(field, value)); } else if (getTarget() != null) { Object value = getActualFieldValue(fixedField(field)); return formatFieldValue(field, value); } else { return this.fieldValues.get(field); } }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof BindingResult)) { return false; } BindingResult otherResult = (BindingResult) other; return (getObjectName().equals(otherResult.getObjectName()) && ObjectUtils.nullSafeEquals(getTarget(), otherResult.getTarget()) && getAllErrors().equals(otherResult.getAllErrors())); }
@Override @Nullable public Object getFieldValue(String field) { FieldError fieldError = getFieldError(field); // Use rejected value in case of error, current field value otherwise. if (fieldError != null) { Object value = fieldError.getRejectedValue(); // Do not apply formatting on binding failures like type mismatches. return (fieldError.isBindingFailure() || getTarget() == null ? value : formatFieldValue(field, value)); } else if (getTarget() != null) { Object value = getActualFieldValue(fixedField(field)); return formatFieldValue(field, value); } else { return this.fieldValues.get(field); } }
/** * This default implementation determines the type based on the actual * field value, if any. Subclasses should override this to determine * the type from a descriptor, even for {@code null} values. * @see #getActualFieldValue */ @Override @Nullable public Class<?> getFieldType(@Nullable String field) { if (getTarget() != null) { Object value = getActualFieldValue(fixedField(field)); if (value != null) { return value.getClass(); } } return this.fieldTypes.get(field); }
@Override @Nullable public Object getRawFieldValue(String field) { return (getTarget() != null ? getActualFieldValue(fixedField(field)) : null); }
/** * Return a model Map for the obtained state, exposing an Errors * instance as '{@link #MODEL_KEY_PREFIX MODEL_KEY_PREFIX} + objectName' * and the object itself. * <p>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. * <p>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, * which needs access to the Errors instance. * @see #getObjectName * @see #MODEL_KEY_PREFIX */ @Override public Map<String, Object> getModel() { Map<String, Object> model = new LinkedHashMap<>(2); // Mapping from name to target object. model.put(getObjectName(), getTarget()); // Errors instance, even if no errors. model.put(MODEL_KEY_PREFIX + getObjectName(), this); return model; }
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof BindingResult)) { return false; } BindingResult otherResult = (BindingResult) other; return (getObjectName().equals(otherResult.getObjectName()) && ObjectUtils.nullSafeEquals(getTarget(), otherResult.getTarget()) && getAllErrors().equals(otherResult.getAllErrors())); }
@Override @Nullable public Object getFieldValue(String field) { FieldError fieldError = getFieldError(field); // Use rejected value in case of error, current field value otherwise. if (fieldError != null) { Object value = fieldError.getRejectedValue(); // Do not apply formatting on binding failures like type mismatches. return (fieldError.isBindingFailure() || getTarget() == null ? value : formatFieldValue(field, value)); } else if (getTarget() != null) { Object value = getActualFieldValue(fixedField(field)); return formatFieldValue(field, value); } else { return this.fieldValues.get(field); } }