Example usage for org.springframework.core.convert.support ConvertingPropertyEditorAdapter ConvertingPropertyEditorAdapter

List of usage examples for org.springframework.core.convert.support ConvertingPropertyEditorAdapter ConvertingPropertyEditorAdapter

Introduction

In this page you can find the example usage for org.springframework.core.convert.support ConvertingPropertyEditorAdapter ConvertingPropertyEditorAdapter.

Prototype

public ConvertingPropertyEditorAdapter(ConversionService conversionService, TypeDescriptor targetDescriptor) 

Source Link

Document

Create a new ConvertingPropertyEditorAdapter for a given org.springframework.core.convert.ConversionService and the given target type.

Usage

From source file:org.springframework.springfaces.mvc.bind.ReverseDataBinder.java

/**
 * Find a property editor by searching custom editors or falling back to default editors.
 * @param propertyName the property name or <tt>null</tt> if looking for an editor for all properties of the given
 * type/* w w w  .j av  a  2 s  .c  o  m*/
 * @param propertyEditorRegistrySupport an optional {@link PropertyEditorRegistrySupport} instance. If <tt>null</tt>
 * a {@link SimpleTypeConverter} instance will be used
 * @param targetObject the target object or <tt>null</tt>
 * @param requiredType the required type.
 * @param typeDescriptor the type descriptor
 * @return the corresponding editor, or <code>null</code> if none
 */
protected PropertyEditor findEditor(String propertyName,
        PropertyEditorRegistrySupport propertyEditorRegistrySupport, Object targetObject, Class<?> requiredType,
        TypeDescriptor typeDescriptor) {

    Assert.notNull(requiredType, "RequiredType must not be null");
    Assert.notNull(typeDescriptor, "TypeDescription must not be null");

    // Use the custom editor if there is one
    PropertyEditor editor = this.dataBinder.findCustomEditor(requiredType, propertyName);
    if (editor != null) {
        return editor;
    }

    // Use the conversion service
    ConversionService conversionService = this.dataBinder.getConversionService();
    if (conversionService != null) {
        if (conversionService.canConvert(TypeDescriptor.valueOf(String.class), typeDescriptor)) {
            return new ConvertingPropertyEditorAdapter(conversionService, typeDescriptor);
        }
    }

    // Fall back to default editors
    if (propertyEditorRegistrySupport == null) {
        propertyEditorRegistrySupport = getSimpleTypeConverter();
    }
    return findDefaultEditor(propertyEditorRegistrySupport, targetObject, requiredType, typeDescriptor);
}