Search in sources :

Example 1 with ConvertingPropertyEditorAdapter

use of org.springframework.core.convert.support.ConvertingPropertyEditorAdapter in project spring-framework by spring-projects.

the class AbstractPropertyBindingResult method findEditor.

/**
	 * This implementation exposes a PropertyEditor adapter for a Formatter,
	 * if applicable.
	 */
@Override
public PropertyEditor findEditor(String field, 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) {
            TypeDescriptor ptd = getPropertyAccessor().getPropertyTypeDescriptor(fixedField(field));
            if (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;
}
Also used : ConvertingPropertyEditorAdapter(org.springframework.core.convert.support.ConvertingPropertyEditorAdapter) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) PropertyEditor(java.beans.PropertyEditor)

Aggregations

PropertyEditor (java.beans.PropertyEditor)1 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)1 ConvertingPropertyEditorAdapter (org.springframework.core.convert.support.ConvertingPropertyEditorAdapter)1