Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
d6bab3b6
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d6bab3b6
编写于
11月 11, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
turned FormattingPropertyEditorAdapter into ConvertingPropertyEditorAdapter
上级
f8dd5fb5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
83 addition
and
7 deletion
+83
-7
org.springframework.context/src/main/java/org/springframework/validation/AbstractPropertyBindingResult.java
...ngframework/validation/AbstractPropertyBindingResult.java
+2
-2
org.springframework.context/src/main/java/org/springframework/validation/DataBinder.java
.../main/java/org/springframework/validation/DataBinder.java
+15
-5
org.springframework.core/src/main/java/org/springframework/core/convert/support/ConvertingPropertyEditorAdapter.java
...core/convert/support/ConvertingPropertyEditorAdapter.java
+66
-0
未找到文件。
org.springframework.context/src/main/java/org/springframework/validation/AbstractPropertyBindingResult.java
浏览文件 @
d6bab3b6
...
...
@@ -24,7 +24,7 @@ import org.springframework.beans.PropertyAccessorUtils;
import
org.springframework.beans.PropertyEditorRegistry
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.
format.support.Format
tingPropertyEditorAdapter
;
import
org.springframework.
core.convert.support.Conver
tingPropertyEditorAdapter
;
import
org.springframework.util.Assert
;
/**
...
...
@@ -151,7 +151,7 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul
TypeDescriptor
td
=
(
field
!=
null
?
getPropertyAccessor
().
getPropertyTypeDescriptor
(
fixedField
(
field
))
:
TypeDescriptor
.
valueOf
(
valueType
));
editor
=
new
FormattingPropertyEditorAdapter
(
this
.
conversionService
,
valueType
);
editor
=
new
ConvertingPropertyEditorAdapter
(
this
.
conversionService
,
td
);
}
return
editor
;
}
...
...
org.springframework.context/src/main/java/org/springframework/validation/DataBinder.java
浏览文件 @
d6bab3b6
...
...
@@ -22,6 +22,7 @@ import java.util.Map;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.ConfigurablePropertyAccessor
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.beans.PropertyAccessException
;
...
...
@@ -459,17 +460,25 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
return
this
.
validator
;
}
//---------------------------------------------------------------------
// Implementation of PropertyEditorRegistry/TypeConverter interface
//---------------------------------------------------------------------
/**
* S
et the ConversionService to use for field value formatting in preference to JavaBeans PropertyEditors.
*
@since 3.0
* S
pecify a Spring 3.0 ConversionService to use for converting
*
property values, as an alternative to JavaBeans PropertyEditors.
*/
public
void
setConversionService
(
ConversionService
conversionService
)
{
this
.
conversionService
=
conversionService
;
}
//---------------------------------------------------------------------
// Implementation of PropertyEditorRegistry/TypeConverter interface
//---------------------------------------------------------------------
/**
* Return the associated ConversionService, if any.
*/
public
ConversionService
getConversionService
()
{
return
this
.
conversionService
;
}
@SuppressWarnings
(
"unchecked"
)
public
void
registerCustomEditor
(
Class
requiredType
,
PropertyEditor
propertyEditor
)
{
...
...
@@ -492,6 +501,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
public
<
T
>
T
convertIfNecessary
(
Object
value
,
Class
<
T
>
requiredType
,
MethodParameter
methodParam
)
throws
TypeMismatchException
{
return
getTypeConverter
().
convertIfNecessary
(
value
,
requiredType
,
methodParam
);
}
...
...
org.springframework.co
ntext/src/main/java/org/springframework/format/support/Format
tingPropertyEditorAdapter.java
→
org.springframework.co
re/src/main/java/org/springframework/core/convert/support/Conver
tingPropertyEditorAdapter.java
浏览文件 @
d6bab3b6
...
...
@@ -14,46 +14,53 @@
* limitations under the License.
*/
package
org.springframework.
forma
t.support
;
package
org.springframework.
core.conver
t.support
;
import
java.beans.PropertyEditorSupport
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.core.convert.TypeDescriptor
;
import
org.springframework.util.Assert
;
/**
* Adapter that exposes a {@link java.beans.PropertyEditor} for any given
* {@link org.springframework.format.Formatter}, retrieving the current
* Locale from {@link org.springframework.context.i18n.LocaleContextHolder}.
* {@link org.springframework.core.convert.ConversionService} and specific target type.
*
* @author Juergen Hoeller
* @since 3.0
*/
public
class
FormattingPropertyEditorAdapter
extends
PropertyEditorSupport
{
public
class
ConvertingPropertyEditorAdapter
extends
PropertyEditorSupport
{
private
static
final
TypeDescriptor
stringDescriptor
=
TypeDescriptor
.
valueOf
(
String
.
class
);
private
final
ConversionService
conversionService
;
private
final
Class
<?>
fieldType
;
private
final
TypeDescriptor
targetDescriptor
;
/**
* Create a new FormattingPropertyEditorAdapter for the given Formatter.
* @param formatter the Formatter to wrap
* Create a new ConvertingPropertyEditorAdapter for a given
* {@link org.springframework.core.convert.ConversionService}
* and the given target type.
* @param conversionService the ConversionService to delegate to
* @param targetDescriptor the target type to convert to
*/
public
FormattingPropertyEditorAdapter
(
ConversionService
formattingService
,
Class
<?>
fieldType
)
{
Assert
.
notNull
(
formatting
Service
,
"ConversionService must not be null"
);
Assert
.
notNull
(
formattingService
,
"FieldType
must not be null"
);
this
.
conversionService
=
formatting
Service
;
this
.
fieldType
=
fieldType
;
public
ConvertingPropertyEditorAdapter
(
ConversionService
conversionService
,
TypeDescriptor
targetDescriptor
)
{
Assert
.
notNull
(
conversion
Service
,
"ConversionService must not be null"
);
Assert
.
notNull
(
targetDescriptor
,
"TypeDescriptor
must not be null"
);
this
.
conversionService
=
conversion
Service
;
this
.
targetDescriptor
=
targetDescriptor
;
}
@Override
public
void
setAsText
(
String
text
)
throws
IllegalArgumentException
{
setValue
(
this
.
conversionService
.
convert
(
text
,
this
.
fieldType
));
setValue
(
this
.
conversionService
.
convert
(
text
,
stringDescriptor
,
this
.
targetDescriptor
));
}
@Override
public
String
getAsText
()
{
return
this
.
conversionService
.
convert
(
getValue
(),
String
.
class
);
return
(
String
)
this
.
conversionService
.
convert
(
getValue
(),
this
.
targetDescriptor
,
stringDescriptor
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录