/** * Returns the underlying PropertyAccessor. * @see #getPropertyAccessor() */ @Override public PropertyEditorRegistry getPropertyEditorRegistry() { return (getTarget() != null ? getPropertyAccessor() : null); }
/** * Return the underlying PropertyAccessor of this binder's BindingResult. */ protected ConfigurablePropertyAccessor getPropertyAccessor() { return getInternalBindingResult().getPropertyAccessor(); }
/** * Fetches the field value from the PropertyAccessor. * @see #getPropertyAccessor() */ @Override @Nullable protected Object getActualFieldValue(String field) { return getPropertyAccessor().getPropertyValue(field); }
/** * Retrieve the custom PropertyEditor for the given field, if any. * @param fixedField the fully qualified field name * @return the custom PropertyEditor, or {@code null} */ @Nullable protected PropertyEditor getCustomEditor(String fixedField) { Class<?> targetType = getPropertyAccessor().getPropertyType(fixedField); PropertyEditor editor = getPropertyAccessor().findCustomEditor(targetType, fixedField); if (editor == null) { editor = BeanUtils.findEditorByConvention(targetType); } return editor; }
public void initConversion(ConversionService conversionService) { Assert.notNull(conversionService, "ConversionService must not be null"); this.conversionService = conversionService; if (getTarget() != null) { getPropertyAccessor().setConversionService(conversionService); } }
/** * Fetches the field value from the PropertyAccessor. * @see #getPropertyAccessor() */ @Override @Nullable protected Object getActualFieldValue(String field) { return getPropertyAccessor().getPropertyValue(field); }
/** * Return the underlying PropertyAccessor of this binder's BindingResult. */ protected ConfigurablePropertyAccessor getPropertyAccessor() { return getInternalBindingResult().getPropertyAccessor(); }
/** * Returns the underlying PropertyAccessor. * @see #getPropertyAccessor() */ @Override public PropertyEditorRegistry getPropertyEditorRegistry() { return (getTarget() != null ? getPropertyAccessor() : null); }
/** * Determines the field type from the property type. * @see #getPropertyAccessor() */ @Override @Nullable public Class<?> getFieldType(@Nullable String field) { return (getTarget() != null ? getPropertyAccessor().getPropertyType(fixedField(field)) : super.getFieldType(field)); }
public void initConversion(ConversionService conversionService) { Assert.notNull(conversionService, "ConversionService must not be null"); this.conversionService = conversionService; if (getTarget() != null) { getPropertyAccessor().setConversionService(conversionService); } }
/** * Retrieve the custom PropertyEditor for the given field, if any. * @param fixedField the fully qualified field name * @return the custom PropertyEditor, or {@code null} */ @Nullable protected PropertyEditor getCustomEditor(String fixedField) { Class<?> targetType = getPropertyAccessor().getPropertyType(fixedField); PropertyEditor editor = getPropertyAccessor().findCustomEditor(targetType, fixedField); if (editor == null) { editor = BeanUtils.findEditorByConvention(targetType); } return editor; }
/** * Return the underlying TypeConverter of this binder's BindingResult. */ protected PropertyEditorRegistry getPropertyEditorRegistry() { if (getTarget() != null) { return getInternalBindingResult().getPropertyAccessor(); } else { return getSimpleTypeConverter(); } }
/** * Return the underlying TypeConverter of this binder's BindingResult. */ protected TypeConverter getTypeConverter() { if (getTarget() != null) { return getInternalBindingResult().getPropertyAccessor(); } else { return getSimpleTypeConverter(); } }
/** * Determines the field type from the property type. * @see #getPropertyAccessor() */ @Override @Nullable public Class<?> getFieldType(@Nullable String field) { return (getTarget() != null ? getPropertyAccessor().getPropertyType(fixedField(field)) : super.getFieldType(field)); }
/** * Return the underlying TypeConverter of this binder's BindingResult. */ protected TypeConverter getTypeConverter() { if (getTarget() != null) { return getInternalBindingResult().getPropertyAccessor(); } else { return getSimpleTypeConverter(); } }
/** * Return the underlying TypeConverter of this binder's BindingResult. */ protected PropertyEditorRegistry getPropertyEditorRegistry() { if (getTarget() != null) { return getInternalBindingResult().getPropertyAccessor(); } else { return getSimpleTypeConverter(); } }
/** * This implementation exposes a PropertyEditor adapter for a Formatter, * if applicable. */ @Override @Nullable public PropertyEditor findEditor(@Nullable String field, @Nullable Class<?> valueType) { Class<?> valueTypeForLookup = valueType; if (valueTypeForLookup == null) { valueTypeForLookup = getFieldType(field); } PropertyEditor editor = super.findEditor(field, valueTypeForLookup); if (editor == null && this.conversionService != null) { TypeDescriptor td = null; if (field != null && getTarget() != null) { TypeDescriptor ptd = getPropertyAccessor().getPropertyTypeDescriptor(fixedField(field)); if (ptd != null && (valueType == null || valueType.isAssignableFrom(ptd.getType()))) { td = ptd; } } if (td == null) { td = TypeDescriptor.valueOf(valueTypeForLookup); } if (this.conversionService.canConvert(TypeDescriptor.valueOf(String.class), td)) { editor = new ConvertingPropertyEditorAdapter(this.conversionService, td); } } return editor; }
/** * Formats the field value based on registered PropertyEditors. * @see #getCustomEditor */ @Override protected Object formatFieldValue(String field, @Nullable Object value) { String fixedField = fixedField(field); // Try custom editor... PropertyEditor customEditor = getCustomEditor(fixedField); if (customEditor != null) { customEditor.setValue(value); String textValue = customEditor.getAsText(); // If the PropertyEditor returned null, there is no appropriate // text representation for this value: only use it if non-null. if (textValue != null) { return textValue; } } if (this.conversionService != null) { // Try custom converter... TypeDescriptor fieldDesc = getPropertyAccessor().getPropertyTypeDescriptor(fixedField); TypeDescriptor strDesc = TypeDescriptor.valueOf(String.class); if (fieldDesc != null && this.conversionService.canConvert(fieldDesc, strDesc)) { return this.conversionService.convert(value, fieldDesc, strDesc); } } return value; }
/** * Formats the field value based on registered PropertyEditors. * @see #getCustomEditor */ @Override protected Object formatFieldValue(String field, @Nullable Object value) { String fixedField = fixedField(field); // Try custom editor... PropertyEditor customEditor = getCustomEditor(fixedField); if (customEditor != null) { customEditor.setValue(value); String textValue = customEditor.getAsText(); // If the PropertyEditor returned null, there is no appropriate // text representation for this value: only use it if non-null. if (textValue != null) { return textValue; } } if (this.conversionService != null) { // Try custom converter... TypeDescriptor fieldDesc = getPropertyAccessor().getPropertyTypeDescriptor(fixedField); TypeDescriptor strDesc = TypeDescriptor.valueOf(String.class); if (fieldDesc != null && this.conversionService.canConvert(fieldDesc, strDesc)) { return this.conversionService.convert(value, fieldDesc, strDesc); } } return value; }
@Test // SPR-15009 public void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAccess() { TestBean testBean = new TestBean(); DataBinder binder = new DataBinder(testBean, "testBean"); DefaultMessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver(); messageCodesResolver.setPrefix("errors."); binder.setMessageCodesResolver(messageCodesResolver); binder.setAutoGrowCollectionLimit(512); // allow configuration after set a MessageCodesResolver binder.initBeanPropertyAccess(); MutablePropertyValues mpv = new MutablePropertyValues(); mpv.add("age", "invalid"); binder.bind(mpv); assertEquals("errors.typeMismatch", binder.getBindingResult().getFieldError("age").getCode()); assertEquals(512, BeanWrapper.class.cast(binder.getInternalBindingResult().getPropertyAccessor()).getAutoGrowCollectionLimit()); }