|
|
|
@ -31,12 +31,12 @@ import org.springframework.util.Assert; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ConvertingPropertyEditorAdapter extends PropertyEditorSupport { |
|
|
|
public class ConvertingPropertyEditorAdapter extends PropertyEditorSupport { |
|
|
|
|
|
|
|
|
|
|
|
private static final TypeDescriptor stringDescriptor = TypeDescriptor.valueOf(String.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final ConversionService conversionService; |
|
|
|
private final ConversionService conversionService; |
|
|
|
|
|
|
|
|
|
|
|
private final TypeDescriptor targetDescriptor; |
|
|
|
private final TypeDescriptor targetDescriptor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final boolean canConvertToString; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new ConvertingPropertyEditorAdapter for a given |
|
|
|
* Create a new ConvertingPropertyEditorAdapter for a given |
|
|
|
@ -50,17 +50,23 @@ public class ConvertingPropertyEditorAdapter extends PropertyEditorSupport { |
|
|
|
Assert.notNull(targetDescriptor, "TypeDescriptor must not be null"); |
|
|
|
Assert.notNull(targetDescriptor, "TypeDescriptor must not be null"); |
|
|
|
this.conversionService = conversionService; |
|
|
|
this.conversionService = conversionService; |
|
|
|
this.targetDescriptor = targetDescriptor; |
|
|
|
this.targetDescriptor = targetDescriptor; |
|
|
|
|
|
|
|
this.canConvertToString = conversionService.canConvert(this.targetDescriptor, TypeDescriptor.STRING); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setAsText(String text) throws IllegalArgumentException { |
|
|
|
public void setAsText(String text) throws IllegalArgumentException { |
|
|
|
setValue(this.conversionService.convert(text, stringDescriptor, this.targetDescriptor)); |
|
|
|
setValue(this.conversionService.convert(text, TypeDescriptor.STRING, this.targetDescriptor)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String getAsText() { |
|
|
|
public String getAsText() { |
|
|
|
return (String) this.conversionService.convert(getValue(), this.targetDescriptor, stringDescriptor); |
|
|
|
if (this.canConvertToString) { |
|
|
|
|
|
|
|
return (String) this.conversionService.convert(getValue(), this.targetDescriptor, TypeDescriptor.STRING); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|