Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
3b68cde3
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,发现更多精彩内容 >>
提交
3b68cde3
编写于
6月 26, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
alerts static factory
上级
18412ae2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
139 addition
and
28 deletion
+139
-28
org.springframework.context/src/main/java/org/springframework/ui/alert/Alert.java
...ext/src/main/java/org/springframework/ui/alert/Alert.java
+0
-6
org.springframework.context/src/main/java/org/springframework/ui/alert/AlertContext.java
.../main/java/org/springframework/ui/alert/AlertContext.java
+3
-2
org.springframework.context/src/main/java/org/springframework/ui/alert/Alerts.java
...xt/src/main/java/org/springframework/ui/alert/Alerts.java
+111
-0
org.springframework.context/src/main/java/org/springframework/ui/alert/support/DefaultAlertContext.java
...springframework/ui/alert/support/DefaultAlertContext.java
+2
-2
org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java
...org/springframework/ui/binding/support/GenericBinder.java
+22
-17
org.springframework.context/src/main/java/org/springframework/ui/lifecycle/BindAndValidateLifecycle.java
...pringframework/ui/lifecycle/BindAndValidateLifecycle.java
+1
-1
未找到文件。
org.springframework.context/src/main/java/org/springframework/ui/alert/Alert.java
浏览文件 @
3b68cde3
...
...
@@ -18,17 +18,11 @@ package org.springframework.ui.alert;
/**
* Communicates an event of interest to the user.
* For example, an alert may inform a user of a web application a business rule was violated.
* TODO - should we introduce detail messages here
* @author Keith Donald
* @since 3.0
*/
public
interface
Alert
{
/**
* The user interface element this alert is associated with; for example, "registration.password"
*/
public
String
getElement
();
/**
* The code uniquely identifying this kind of alert; for example, "weakPassword".
* May be used as a key to lookup additional alert details.
...
...
org.springframework.context/src/main/java/org/springframework/ui/alert/AlertContext.java
浏览文件 @
3b68cde3
...
...
@@ -41,8 +41,9 @@ public interface AlertContext {
/**
* Add an alert to this context.
* @param the element this alert is associated with
* @param alert the alert to add
*/
public
void
add
(
Alert
alert
);
public
void
add
(
String
element
,
Alert
alert
);
}
}
\ No newline at end of file
org.springframework.context/src/main/java/org/springframework/ui/alert/Alerts.java
0 → 100644
浏览文件 @
3b68cde3
/*
* Copyright 2004-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.alert
;
/**
* A static factory for conveniently constructing Alerts.
* Usage example:
* <pre>
* static import org.springframework.ui.alert.Alerts;
*
* public void example() {
* info("An info alert");
* warning("A warning alert");
* error("An error alert");
* fatal("A fatal alert");
* }
* </pre>
* @author Keith Donald
* @since 3.0
*/
public
final
class
Alerts
{
/**
* Creates a new info alert.
* @param message the alert message
* @return the info alert
* @see Severity#INFO
*/
public
static
Alert
info
(
String
message
)
{
return
new
GenericAlert
(
Severity
.
INFO
,
null
,
message
);
}
/**
* Creates a new warning alert.
* @param message the alert message
* @return the info alert
* @see Severity#WARNING
*/
public
static
Alert
warning
(
String
message
)
{
return
new
GenericAlert
(
Severity
.
WARNING
,
null
,
message
);
}
/**
* Creates a new error alert.
* @param message the alert message
* @return the info alert
* @see Severity#ERROR
*/
public
static
Alert
error
(
String
message
)
{
return
new
GenericAlert
(
Severity
.
ERROR
,
null
,
message
);
}
/**
* Creates a new fatal alert.
* @param message the alert message
* @return the info alert
* @see Severity#ERROR
*/
public
static
Alert
fatal
(
String
message
)
{
return
new
GenericAlert
(
Severity
.
FATAL
,
null
,
message
);
}
private
static
class
GenericAlert
implements
Alert
{
private
Severity
severity
;
private
String
code
;
private
String
message
;
public
GenericAlert
(
Severity
severity
,
String
code
,
String
message
)
{
this
.
severity
=
severity
;
this
.
code
=
code
;
this
.
message
=
message
;
}
public
Severity
getSeverity
()
{
return
severity
;
}
public
String
getCode
()
{
return
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
String
toString
()
{
if
(
getCode
()
!=
null
)
{
return
getCode
()
+
" - "
+
getMessage
();
}
else
{
return
getMessage
();
}
}
}
}
\ No newline at end of file
org.springframework.context/src/main/java/org/springframework/ui/alert/support/DefaultAlertContext.java
浏览文件 @
3b68cde3
...
...
@@ -54,8 +54,8 @@ public class DefaultAlertContext implements AlertContext {
return
Collections
.
unmodifiableList
(
messages
);
}
public
void
add
(
Alert
alert
)
{
List
<
Alert
>
alerts
=
this
.
alerts
.
get
(
alert
.
getElement
()
);
public
void
add
(
String
element
,
Alert
alert
)
{
List
<
Alert
>
alerts
=
this
.
alerts
.
get
(
element
);
alerts
.
add
(
alert
);
}
...
...
org.springframework.context/src/main/java/org/springframework/ui/binding/support/GenericBinder.java
浏览文件 @
3b68cde3
...
...
@@ -55,6 +55,7 @@ import org.springframework.ui.binding.Binder;
import
org.springframework.ui.binding.Binding
;
import
org.springframework.ui.binding.BindingResult
;
import
org.springframework.ui.binding.BindingResults
;
import
org.springframework.ui.format.AnnotationFormatterFactory
;
import
org.springframework.ui.format.Formatter
;
import
org.springframework.ui.message.MessageBuilder
;
import
org.springframework.ui.message.ResolvableArgument
;
...
...
@@ -176,6 +177,26 @@ public class GenericBinder implements Binder {
return
binding
;
}
/**
* Register a Formatter to format the model properties of a specific property type.
* Convenience method that calls {@link FormatterRegistry#add(Class, Formatter)} internally.
* The type may be a marker annotation type; if so, the Formatter will be used on properties having that marker annotation.
* @param propertyType the model property type
* @param formatter the formatter
*/
public
void
registerFormatter
(
Class
<?>
propertyType
,
Formatter
<?>
formatter
)
{
formatterRegistry
.
add
(
propertyType
,
formatter
);
}
/**
* Register a FormatterFactory that creates Formatter instances as required to format model properties annotated with a specific annotation.
* Convenience method that calls {@link FormatterRegistry#add(AnnotationFormatterFactory)} internally.
* @param factory the formatter factory
*/
public
void
registerFormatterFactory
(
AnnotationFormatterFactory
<?,
?>
factory
)
{
formatterRegistry
.
add
(
factory
);
}
public
Binding
getBinding
(
String
property
)
{
Binding
binding
=
bindings
.
get
(
property
);
if
(
binding
==
null
&&
!
strict
)
{
...
...
@@ -528,10 +549,6 @@ public class GenericBinder implements Binder {
public
Alert
getAlert
()
{
return
new
AbstractAlert
()
{
public
String
getElement
()
{
return
getProperty
();
}
public
String
getCode
()
{
return
"noSuchBinding"
;
}
...
...
@@ -581,10 +598,6 @@ public class GenericBinder implements Binder {
public
Alert
getAlert
()
{
return
new
AbstractAlert
()
{
public
String
getElement
()
{
return
getProperty
();
}
public
String
getCode
()
{
return
"invalidFormat"
;
}
...
...
@@ -635,10 +648,6 @@ public class GenericBinder implements Binder {
public
Alert
getAlert
()
{
return
new
AbstractAlert
()
{
public
String
getElement
()
{
return
getProperty
();
}
public
String
getCode
()
{
SpelMessage
spelCode
=
((
SpelEvaluationException
)
cause
).
getMessageCode
();
if
(
spelCode
==
SpelMessage
.
EXCEPTION_DURING_PROPERTY_WRITE
)
{
...
...
@@ -726,10 +735,6 @@ public class GenericBinder implements Binder {
public
Alert
getAlert
()
{
return
new
AbstractAlert
()
{
public
String
getElement
()
{
return
getProperty
();
}
public
String
getCode
()
{
return
"bindSuccess"
;
}
...
...
@@ -753,7 +758,7 @@ public class GenericBinder implements Binder {
static
abstract
class
AbstractAlert
implements
Alert
{
public
String
toString
()
{
return
get
Element
()
+
":"
+
get
Code
()
+
" - "
+
getMessage
();
return
getCode
()
+
" - "
+
getMessage
();
}
}
}
org.springframework.context/src/main/java/org/springframework/ui/lifecycle/BindAndValidateLifecycle.java
浏览文件 @
3b68cde3
...
...
@@ -50,7 +50,7 @@ public class BindAndValidateLifecycle {
validator
.
validate
(
binder
.
getModel
(),
bindingResults
.
successes
().
properties
());
}
for
(
BindingResult
result
:
bindingResults
.
failures
())
{
alertContext
.
add
(
result
.
getAlert
());
alertContext
.
add
(
result
.
get
Property
(),
result
.
get
Alert
());
}
// TODO translate validation results into messages
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录