Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
6d59dad4
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,发现更多精彩内容 >>
提交
6d59dad4
编写于
6月 13, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
since 3.0; lifecycle pkg
上级
42cdeb43
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
25 deletion
+29
-25
org.springframework.context/src/main/java/org/springframework/ui/format/number/CurrencyFormat.java
.../org/springframework/ui/format/number/CurrencyFormat.java
+1
-0
org.springframework.context/src/main/java/org/springframework/ui/lifecycle/WebBindAndValidateLifecycle.java
...ngframework/ui/lifecycle/WebBindAndValidateLifecycle.java
+28
-25
未找到文件。
org.springframework.context/src/main/java/org/springframework/ui/format/number/CurrencyFormat.java
浏览文件 @
6d59dad4
...
@@ -24,6 +24,7 @@ import java.lang.annotation.Target;
...
@@ -24,6 +24,7 @@ import java.lang.annotation.Target;
/**
/**
* A annotation to apply to a BigDecimal property to have its value formatted as currency amount using a {@link CurrencyFormatter}.
* A annotation to apply to a BigDecimal property to have its value formatted as currency amount using a {@link CurrencyFormatter}.
* @author Keith Donald
* @author Keith Donald
* @since 3.0
*/
*/
@Target
(
{
ElementType
.
METHOD
,
ElementType
.
FIELD
})
@Target
(
{
ElementType
.
METHOD
,
ElementType
.
FIELD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
...
...
org.springframework.context/src/main/java/org/springframework/ui/WebBindAndValidateLifecycle.java
→
org.springframework.context/src/main/java/org/springframework/ui/
lifecycle/
WebBindAndValidateLifecycle.java
浏览文件 @
6d59dad4
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
*/
package
org.springframework.ui
;
package
org.springframework.ui
.lifecycle
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -23,14 +23,18 @@ import org.springframework.ui.binding.UserValues;
...
@@ -23,14 +23,18 @@ import org.springframework.ui.binding.UserValues;
import
org.springframework.ui.binding.support.WebBinder
;
import
org.springframework.ui.binding.support.WebBinder
;
import
org.springframework.ui.message.MessageBuilder
;
import
org.springframework.ui.message.MessageBuilder
;
import
org.springframework.ui.message.MessageContext
;
import
org.springframework.ui.message.MessageContext
;
import
org.springframework.ui.
validation.ValidationResults
;
import
org.springframework.ui.
message.MessageResolver
;
import
org.springframework.ui.validation.Validator
;
import
org.springframework.ui.validation.Validator
;
/**
* Implementation of the bind and validate lifecycle for web (HTTP) environments.
* @author Keith Donald
* @since 3.0
*/
public
class
WebBindAndValidateLifecycle
{
public
class
WebBindAndValidateLifecycle
{
private
final
WebBinder
binder
;
private
final
WebBinder
binder
;
@SuppressWarnings
(
"unused"
)
private
final
MessageContext
messageContext
;
private
final
MessageContext
messageContext
;
private
ValidationDecider
validationDecider
=
ValidationDecider
.
ALWAYS_VALIDATE
;
private
ValidationDecider
validationDecider
=
ValidationDecider
.
ALWAYS_VALIDATE
;
...
@@ -38,6 +42,9 @@ public class WebBindAndValidateLifecycle {
...
@@ -38,6 +42,9 @@ public class WebBindAndValidateLifecycle {
private
Validator
validator
;
private
Validator
validator
;
public
WebBindAndValidateLifecycle
(
Object
model
,
MessageContext
messageContext
)
{
public
WebBindAndValidateLifecycle
(
Object
model
,
MessageContext
messageContext
)
{
// TODO allow binder to be configured with bindings from model metadata
// TODO support @Bound property annotation?
// TODO support @StrictBinding class-level annotation?
this
.
binder
=
new
WebBinder
(
model
);
this
.
binder
=
new
WebBinder
(
model
);
this
.
messageContext
=
messageContext
;
this
.
messageContext
=
messageContext
;
}
}
...
@@ -46,29 +53,24 @@ public class WebBindAndValidateLifecycle {
...
@@ -46,29 +53,24 @@ public class WebBindAndValidateLifecycle {
UserValues
values
=
binder
.
createUserValues
(
userMap
);
UserValues
values
=
binder
.
createUserValues
(
userMap
);
BindingResults
bindingResults
=
binder
.
bind
(
values
);
BindingResults
bindingResults
=
binder
.
bind
(
values
);
if
(
validationDecider
.
shouldValidateAfter
(
bindingResults
))
{
if
(
validationDecider
.
shouldValidateAfter
(
bindingResults
))
{
ValidationResults
validationResults
=
validator
.
validate
(
binder
.
getModel
(),
bindingResults
.
successes
()
// TODO get validation results
.
properties
());
validator
.
validate
(
binder
.
getModel
(),
bindingResults
.
successes
()
.
properties
());
}
}
// TODO translate binding and validation results into messages
MessageBuilder
builder
=
new
MessageBuilder
();
MessageBuilder
builder
=
new
MessageBuilder
();
for
(
BindingResult
result
:
bindingResults
.
failures
())
{
for
(
BindingResult
result
:
bindingResults
.
failures
())
{
builder
.
MessageResolver
message
=
builder
.
code
(
modelPropertyError
(
result
)).
code
(
propertyError
(
result
)).
code
(
code
(
modelPropertyError
(
result
)).
typeError
(
result
)).
code
(
error
(
result
)).
resolvableArg
(
"label"
,
getModelProperty
(
result
)).
arg
(
code
(
propertyError
(
result
)).
"value"
,
result
.
getUserValue
()).
code
(
typeError
(
result
)).
// TODO add binding el resolver allowing binding.format to be called
code
(
error
(
result
)).
arg
(
"binding"
,
binder
.
getBinding
(
result
.
getProperty
())).
//argContextFactory(createContextFactory(bindingResult)).
// TODO allow binding result to contribute additional arguments
// TODO arg names
build
();
// TODO el support including ability to setup evaluation context
// TODO should model name be part of element id?
//resolvableArg("label", getModelProperty(result)).
messageContext
.
add
(
message
,
result
.
getProperty
());
//arg("value", result.getUserValue()).
//arg("binding", binder.getBinding(result.getProperty())).
//args(result.getErrorArguments()).
build
();
}
}
// TODO
expose property Binding in EL context for property error message resolution?
// TODO
translate validation results into messages
}
}
private
String
modelPropertyError
(
BindingResult
result
)
{
private
String
modelPropertyError
(
BindingResult
result
)
{
return
getModelProperty
(
result
)
+
"."
+
result
.
getErrorCode
();
return
getModelProperty
(
result
)
+
"."
+
result
.
getErrorCode
();
}
}
...
@@ -77,20 +79,21 @@ public class WebBindAndValidateLifecycle {
...
@@ -77,20 +79,21 @@ public class WebBindAndValidateLifecycle {
return
result
.
getProperty
()
+
"."
+
result
.
getErrorCode
();
return
result
.
getProperty
()
+
"."
+
result
.
getErrorCode
();
}
}
private
String
typeError
(
BindingResult
result
)
{
private
String
typeError
(
BindingResult
result
)
{
return
binder
.
getBinding
(
result
.
getProperty
()).
getType
().
getName
()
+
"."
+
result
.
getErrorCode
();
return
binder
.
getBinding
(
result
.
getProperty
()).
getType
().
getName
()
+
"."
+
result
.
getErrorCode
();
}
}
private
String
error
(
BindingResult
result
)
{
private
String
error
(
BindingResult
result
)
{
return
result
.
getErrorCode
();
return
result
.
getErrorCode
();
}
}
private
String
getModelProperty
(
BindingResult
result
)
{
private
String
getModelProperty
(
BindingResult
result
)
{
return
getModel
()
+
"."
+
result
.
getProperty
();
return
getModel
()
+
"."
+
result
.
getProperty
();
}
}
private
String
getModel
()
{
private
String
getModel
()
{
// TODO would be nice if model name was module.ClassName by default where module is subpackage of app base package
// TODO would be nice if model name was module.ClassName by default where module is subpackage of app base package
// TODO model name should probably be specifiable using class-level annotation
return
binder
.
getModel
().
getClass
().
getName
();
return
binder
.
getModel
().
getClass
().
getName
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录