Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
7e3c1bf0
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,发现更多精彩内容 >>
提交
7e3c1bf0
编写于
6月 26, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
prepping for jsr 303 integration
上级
0edc3d94
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
70 addition
and
20 deletion
+70
-20
org.springframework.context/src/main/java/org/springframework/ui/binding/support/AnnotatedModelBinderConfigurer.java
...rk/ui/binding/support/AnnotatedModelBinderConfigurer.java
+1
-1
org.springframework.context/src/main/java/org/springframework/ui/binding/support/BindingConfiguration.java
...ingframework/ui/binding/support/BindingConfiguration.java
+1
-1
org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java
...org/springframework/ui/binding/support/GenericBinder.java
+2
-0
org.springframework.context/src/main/java/org/springframework/ui/lifecycle/BindAndValidateLifecycle.java
...pringframework/ui/lifecycle/BindAndValidateLifecycle.java
+22
-17
org.springframework.context/src/main/java/org/springframework/ui/lifecycle/ValidationDecider.java
...a/org/springframework/ui/lifecycle/ValidationDecider.java
+43
-0
org.springframework.context/src/test/java/org/springframework/ui/lifecycle/BindAndValidateLifecycleTests.java
...framework/ui/lifecycle/BindAndValidateLifecycleTests.java
+1
-1
未找到文件。
org.springframework.context/src/main/java/org/springframework/ui/binding/support/AnnotatedModelBinderConfigurer.java
浏览文件 @
7e3c1bf0
...
...
@@ -10,7 +10,7 @@ import org.springframework.core.annotation.AnnotationUtils;
import
org.springframework.ui.binding.Bound
;
import
org.springframework.ui.binding.Model
;
class
AnnotatedModelBinderConfigurer
{
final
class
AnnotatedModelBinderConfigurer
{
public
void
configure
(
GenericBinder
binder
)
{
Class
<?>
modelClass
=
binder
.
getModel
().
getClass
();
...
...
org.springframework.context/src/main/java/org/springframework/ui/binding/support/BindingConfiguration.java
浏览文件 @
7e3c1bf0
...
...
@@ -24,7 +24,7 @@ import org.springframework.ui.format.Formatter;
* @since 3.0
* @see GenericBinder#configureBinding(BindingConfiguration)
*/
public
class
BindingConfiguration
{
public
final
class
BindingConfiguration
{
private
String
property
;
...
...
org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java
浏览文件 @
7e3c1bf0
...
...
@@ -169,6 +169,7 @@ public class GenericBinder implements Binder {
public
Binding
configureBinding
(
BindingConfiguration
configuration
)
{
Binding
binding
;
try
{
// TODO should probably only allow binding to be created if property exists on model
binding
=
new
BindingImpl
(
configuration
);
}
catch
(
org
.
springframework
.
expression
.
ParseException
e
)
{
throw
new
IllegalArgumentException
(
e
);
...
...
@@ -653,6 +654,7 @@ public class GenericBinder implements Binder {
if
(
spelCode
==
SpelMessage
.
EXCEPTION_DURING_PROPERTY_WRITE
)
{
return
"conversionFailed"
;
}
else
if
(
spelCode
==
SpelMessage
.
PROPERTY_OR_FIELD_NOT_READABLE
)
{
// TODO should probably force property exists before even creating binding
return
"propertyNotFound"
;
}
else
{
return
"couldNotSetValue"
;
...
...
org.springframework.context/src/main/java/org/springframework/ui/lifecycle/BindAndValidateLifecycle.java
浏览文件 @
7e3c1bf0
...
...
@@ -24,24 +24,39 @@ import org.springframework.ui.binding.BindingResults;
import
org.springframework.ui.validation.Validator
;
/**
* Implementation of the
bind and validate lifecycle for web (HTTP) environments
.
* Implementation of the
model bind and validate lifecycle lifecycle
.
* @author Keith Donald
* @since 3.0
*/
public
class
BindAndValidateLifecycle
{
public
final
class
BindAndValidateLifecycle
{
private
final
Binder
binder
;
private
Binder
binder
;
private
final
AlertContext
alertContext
;
private
Validator
validator
;
private
ValidationDecider
validationDecider
=
ValidationDecider
.
ALWAYS_VALIDATE
;
private
Validator
validator
;
private
final
AlertContext
alertContext
;
public
BindAndValidateLifecycle
(
Binder
binder
,
AlertContext
alertContext
)
{
/**
* Create a new bind and validate lifecycle.
* @param binder the binder to use for model binding
* @param validator the validator to use for model validation
* @param alertContext a context for adding binding and validation-related alerts
*/
public
BindAndValidateLifecycle
(
Binder
binder
,
Validator
validator
,
AlertContext
alertContext
)
{
this
.
binder
=
binder
;
this
.
validator
=
validator
;
this
.
alertContext
=
alertContext
;
}
/**
* Configures the strategy that determines if validation should execute after binding.
* @param validationDecider the validation decider
*/
public
void
setValidationDecider
(
ValidationDecider
validationDecider
)
{
this
.
validationDecider
=
validationDecider
;
}
public
void
execute
(
Map
<
String
,
?
extends
Object
>
sourceValues
)
{
BindingResults
bindingResults
=
binder
.
bind
(
sourceValues
);
...
...
@@ -50,20 +65,10 @@ public class BindAndValidateLifecycle {
validator
.
validate
(
binder
.
getModel
(),
bindingResults
.
successes
().
properties
());
}
for
(
BindingResult
result
:
bindingResults
.
failures
())
{
// TODO - you may want to ignore some alerts like propertyNotFound
alertContext
.
add
(
result
.
getProperty
(),
result
.
getAlert
());
}
// TODO translate validation results into messages
}
interface
ValidationDecider
{
boolean
shouldValidateAfter
(
BindingResults
results
);
static
final
ValidationDecider
ALWAYS_VALIDATE
=
new
ValidationDecider
()
{
public
boolean
shouldValidateAfter
(
BindingResults
results
)
{
return
true
;
}
};
}
}
org.springframework.context/src/main/java/org/springframework/ui/lifecycle/ValidationDecider.java
0 → 100644
浏览文件 @
7e3c1bf0
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.ui.lifecycle
;
import
org.springframework.ui.binding.BindingResults
;
/**
* Decides if validation should run for an execution of the bind and validate lifecycle.
* @author Keith Donald
* @since 3.0
* @see BindAndValidateLifecycle#execute(java.util.Map)
*/
interface
ValidationDecider
{
/**
* Should validation execute after model binding?
* @param results the results of model binding
* @return yes or no
*/
boolean
shouldValidateAfter
(
BindingResults
results
);
/**
* Singleton reference to a ValidationDecider that always returns true.
*/
static
final
ValidationDecider
ALWAYS_VALIDATE
=
new
ValidationDecider
()
{
public
boolean
shouldValidateAfter
(
BindingResults
results
)
{
return
true
;
}
};
}
\ No newline at end of file
org.springframework.context/src/test/java/org/springframework/ui/lifecycle/BindAndValidateLifecycleTests.java
浏览文件 @
7e3c1bf0
...
...
@@ -31,7 +31,7 @@ public class BindAndValidateLifecycleTests {
model
=
new
TestBean
();
alertContext
=
new
DefaultAlertContext
();
Binder
binder
=
new
WebBinderFactory
().
getBinder
(
model
);
lifecycle
=
new
BindAndValidateLifecycle
(
binder
,
alertContext
);
lifecycle
=
new
BindAndValidateLifecycle
(
binder
,
null
,
alertContext
);
}
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录