Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
ca060cea
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,发现更多精彩内容 >>
提交
ca060cea
编写于
7月 27, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
binder support
上级
880eb9e2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
13 addition
and
30 deletion
+13
-30
org.springframework.context/src/main/java/org/springframework/model/binder/support/BinderSupport.java
...g/springframework/model/binder/support/BinderSupport.java
+3
-11
org.springframework.context/src/main/java/org/springframework/model/binder/support/GenericBinder.java
...g/springframework/model/binder/support/GenericBinder.java
+7
-17
org.springframework.context/src/main/java/org/springframework/model/ui/support/PresentationModelBinder.java
...ngframework/model/ui/support/PresentationModelBinder.java
+3
-2
未找到文件。
org.springframework.context/src/main/java/org/springframework/model/binder/support/
AbstractBinder
.java
→
org.springframework.context/src/main/java/org/springframework/model/binder/support/
BinderSupport
.java
浏览文件 @
ca060cea
...
...
@@ -15,32 +15,26 @@
*/
package
org.springframework.model.binder.support
;
import
java.util.Map
;
import
org.springframework.context.MessageSource
;
import
org.springframework.model.binder.Binder
;
import
org.springframework.model.binder.BindingResult
;
import
org.springframework.model.binder.BindingResults
;
import
org.springframework.model.binder.MissingFieldException
;
import
org.springframework.util.Assert
;
/**
* Base Binder implementation that defines common structural elements.
* Subclasses should parameterized & implement {@link #bind(Map, Object)}.
* Binder implementation support class that defines common structural elements.
* @author Keith Donald
* @since 3.0
* @see #setRequiredFields(String[])
* @see #setMessageSource(MessageSource)
* @see #createBindTemplate()
* @see #bind(Map, Object)
*/
public
abstract
class
AbstractBinder
<
M
>
implements
Binder
<
M
>
{
public
abstract
class
BinderSupport
{
private
BindTemplate
bindTemplate
;
private
MessageSource
messageSource
;
public
AbstractBinder
()
{
public
BinderSupport
()
{
bindTemplate
=
createBindTemplate
();
}
...
...
@@ -62,8 +56,6 @@ public abstract class AbstractBinder<M> implements Binder<M> {
this
.
messageSource
=
messageSource
;
}
public
abstract
BindingResults
bind
(
Map
<
String
,
?
extends
Object
>
fieldValues
,
M
model
);
// subclass hooks
/**
...
...
org.springframework.context/src/main/java/org/springframework/model/binder/support/GenericBinder.java
浏览文件 @
ca060cea
...
...
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.model.binder.support
;
import
java.util.Map
;
...
...
@@ -36,26 +35,22 @@ import org.springframework.model.binder.BindingResults;
* A {@link Binder} implementation that accepts any target object and uses
* Spring's Expression Language support to evaluate the keys in the field
* value Map.
*
* @author Mark Fisher
* @since 3.0
*/
public
class
GenericBinder
extends
Abstract
Binder
<
Object
>
{
public
class
GenericBinder
extends
BinderSupport
implements
Binder
<
Object
>
{
private
final
ExpressionParser
parser
=
new
SpelExpressionParser
(
SpelExpressionParserConfiguration
.
CreateObjectIfAttemptToReferenceNull
|
SpelExpressionParserConfiguration
.
GrowListsOnIndexBeyondSize
);
SpelExpressionParserConfiguration
.
CreateObjectIfAttemptToReferenceNull
|
SpelExpressionParserConfiguration
.
GrowListsOnIndexBeyondSize
);
@Override
public
BindingResults
bind
(
Map
<
String
,
?
extends
Object
>
fieldValues
,
Object
model
)
{
StandardEvaluationContext
evaluationContext
=
new
StandardEvaluationContext
();
evaluationContext
.
setRootObject
(
model
);
FieldBinder
fieldBinder
=
new
EvaluationContextFieldBinder
(
this
.
parser
,
evaluationContext
);
return
this
.
getBindTemplate
().
bind
(
fieldValues
,
fieldBinder
);
FieldBinder
fieldBinder
=
new
EvaluationContextFieldBinder
(
parser
,
evaluationContext
);
return
getBindTemplate
().
bind
(
fieldValues
,
fieldBinder
);
}
private
static
class
EvaluationContextFieldBinder
implements
FieldBinder
{
private
final
ExpressionParser
parser
;
...
...
@@ -73,18 +68,15 @@ public class GenericBinder extends AbstractBinder<Object> {
Expression
e
=
this
.
parser
.
parseExpression
(
key
);
e
.
setValue
(
this
.
context
,
value
);
alert
=
new
BindSuccessAlert
();
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
alert
=
new
ParseFailureAlert
(
e
);
}
catch
(
EvaluationException
e
)
{
}
catch
(
EvaluationException
e
)
{
alert
=
new
EvaluationFailureAlert
(
e
);
}
return
new
AlertBindingResult
(
key
,
value
,
alert
);
}
}
private
static
class
BindSuccessAlert
implements
Alert
{
public
String
getCode
()
{
...
...
@@ -100,7 +92,6 @@ public class GenericBinder extends AbstractBinder<Object> {
}
}
private
static
class
ParseFailureAlert
implements
Alert
{
private
final
ParseException
exception
;
...
...
@@ -122,7 +113,6 @@ public class GenericBinder extends AbstractBinder<Object> {
}
}
private
static
class
EvaluationFailureAlert
implements
Alert
{
private
final
EvaluationException
exception
;
...
...
org.springframework.context/src/main/java/org/springframework/model/ui/support/PresentationModelBinder.java
浏览文件 @
ca060cea
...
...
@@ -18,10 +18,11 @@ package org.springframework.model.ui.support;
import
java.util.Map
;
import
org.springframework.context.MessageSource
;
import
org.springframework.model.binder.Binder
;
import
org.springframework.model.binder.BindingResult
;
import
org.springframework.model.binder.BindingResults
;
import
org.springframework.model.binder.support.AbstractBinder
;
import
org.springframework.model.binder.support.AlertBindingResult
;
import
org.springframework.model.binder.support.BinderSupport
;
import
org.springframework.model.binder.support.FieldBinder
;
import
org.springframework.model.binder.support.FieldNotEditableResult
;
import
org.springframework.model.binder.support.FieldNotFoundResult
;
...
...
@@ -38,7 +39,7 @@ import org.springframework.model.ui.PresentationModel;
* @see #setRequiredFields(String[])
* @see #bind(Map, PresentationModel)
*/
public
class
PresentationModelBinder
extends
Abstract
Binder
<
PresentationModel
>
{
public
class
PresentationModelBinder
extends
BinderSupport
implements
Binder
<
PresentationModel
>
{
public
BindingResults
bind
(
Map
<
String
,
?
extends
Object
>
fieldValues
,
PresentationModel
model
)
{
fieldValues
=
filter
(
fieldValues
,
model
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录