Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
b3b4c7aa
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,体验更适合开发者的 AI 搜索 >>
提交
b3b4c7aa
编写于
2月 15, 2010
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed checkboxes comparison for multi-list (SPR-6505)
上级
cdee5381
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
5 deletion
+57
-5
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/form/CheckboxesTagTests.java
...ngframework/web/servlet/tags/form/CheckboxesTagTests.java
+54
-2
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/form/SelectTagTests.java
...springframework/web/servlet/tags/form/SelectTagTests.java
+3
-3
未找到文件。
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/form/CheckboxesTagTests.java
浏览文件 @
b3b4c7aa
/*
* Copyright 2002-20
08
the original author or authors.
* Copyright 2002-20
10
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.
...
...
@@ -18,15 +18,16 @@ package org.springframework.web.servlet.tags.form;
import
java.beans.PropertyEditorSupport
;
import
java.io.StringReader
;
import
java.text.ParseException
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.servlet.jsp.tagext.Tag
;
import
org.dom4j.Document
;
...
...
@@ -37,6 +38,8 @@ import org.springframework.beans.Colour;
import
org.springframework.beans.Pet
;
import
org.springframework.beans.TestBean
;
import
org.springframework.beans.propertyeditors.StringTrimmerEditor
;
import
org.springframework.format.Formatter
;
import
org.springframework.format.support.FormattingConversionService
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.validation.BeanPropertyBindingResult
;
import
org.springframework.validation.BindingResult
;
...
...
@@ -414,6 +417,55 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
assertEquals
(
"BAZ"
,
checkboxElement3
.
attribute
(
"value"
).
getValue
());
}
public
void
testWithMultiValueWithFormatter
()
throws
Exception
{
this
.
tag
.
setPath
(
"stringArray"
);
this
.
tag
.
setItems
(
new
Object
[]
{
" foo"
,
" bar"
,
" baz"
});
BeanPropertyBindingResult
bindingResult
=
new
BeanPropertyBindingResult
(
this
.
bean
,
COMMAND_NAME
);
FormattingConversionService
cs
=
new
FormattingConversionService
();
cs
.
addFormatterForFieldType
(
String
.
class
,
new
Formatter
<
String
>()
{
public
String
print
(
String
object
,
Locale
locale
)
{
return
object
;
}
public
String
parse
(
String
text
,
Locale
locale
)
throws
ParseException
{
return
text
.
trim
();
}
});
bindingResult
.
initConversion
(
cs
);
getPageContext
().
getRequest
().
setAttribute
(
BindingResult
.
MODEL_KEY_PREFIX
+
COMMAND_NAME
,
bindingResult
);
int
result
=
this
.
tag
.
doStartTag
();
assertEquals
(
Tag
.
SKIP_BODY
,
result
);
String
output
=
getOutput
();
// wrap the output so it is valid XML
output
=
"<doc>"
+
output
+
"</doc>"
;
SAXReader
reader
=
new
SAXReader
();
Document
document
=
reader
.
read
(
new
StringReader
(
output
));
Element
spanElement1
=
(
Element
)
document
.
getRootElement
().
elements
().
get
(
0
);
Element
checkboxElement1
=
(
Element
)
spanElement1
.
elements
().
get
(
0
);
assertEquals
(
"input"
,
checkboxElement1
.
getName
());
assertEquals
(
"checkbox"
,
checkboxElement1
.
attribute
(
"type"
).
getValue
());
assertEquals
(
"stringArray"
,
checkboxElement1
.
attribute
(
"name"
).
getValue
());
assertEquals
(
"checked"
,
checkboxElement1
.
attribute
(
"checked"
).
getValue
());
assertEquals
(
" foo"
,
checkboxElement1
.
attribute
(
"value"
).
getValue
());
Element
spanElement2
=
(
Element
)
document
.
getRootElement
().
elements
().
get
(
1
);
Element
checkboxElement2
=
(
Element
)
spanElement2
.
elements
().
get
(
0
);
assertEquals
(
"input"
,
checkboxElement2
.
getName
());
assertEquals
(
"checkbox"
,
checkboxElement2
.
attribute
(
"type"
).
getValue
());
assertEquals
(
"stringArray"
,
checkboxElement2
.
attribute
(
"name"
).
getValue
());
assertEquals
(
"checked"
,
checkboxElement2
.
attribute
(
"checked"
).
getValue
());
assertEquals
(
" bar"
,
checkboxElement2
.
attribute
(
"value"
).
getValue
());
Element
spanElement3
=
(
Element
)
document
.
getRootElement
().
elements
().
get
(
2
);
Element
checkboxElement3
=
(
Element
)
spanElement3
.
elements
().
get
(
0
);
assertEquals
(
"input"
,
checkboxElement3
.
getName
());
assertEquals
(
"checkbox"
,
checkboxElement3
.
attribute
(
"type"
).
getValue
());
assertEquals
(
"stringArray"
,
checkboxElement3
.
attribute
(
"name"
).
getValue
());
assertNull
(
"not checked"
,
checkboxElement3
.
attribute
(
"checked"
));
assertEquals
(
" baz"
,
checkboxElement3
.
attribute
(
"value"
).
getValue
());
}
public
void
testCollectionOfPets
()
throws
Exception
{
this
.
tag
.
setPath
(
"pets"
);
List
allPets
=
new
ArrayList
();
...
...
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/form/SelectTagTests.java
浏览文件 @
b3b4c7aa
/*
* Copyright 2002-20
08
the original author or authors.
* Copyright 2002-20
10
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.
...
...
@@ -463,7 +463,7 @@ public class SelectTagTests extends AbstractFormTagTests {
assertEquals
(
"Austria(AT)"
,
e
.
getText
());
}
public
void
testWithElement
Conver
ter
()
throws
Exception
{
public
void
testWithElement
Format
ter
()
throws
Exception
{
this
.
bean
.
setRealCountry
(
Country
.
COUNTRY_UK
);
BeanPropertyBindingResult
errors
=
new
BeanPropertyBindingResult
(
this
.
bean
,
COMMAND_NAME
);
...
...
@@ -505,7 +505,7 @@ public class SelectTagTests extends AbstractFormTagTests {
assertEquals
(
"United Kingdom"
,
e
.
getText
());
}
public
void
testWithMultiListAndElement
Conver
ter
()
throws
Exception
{
public
void
testWithMultiListAndElement
Format
ter
()
throws
Exception
{
List
list
=
new
ArrayList
();
list
.
add
(
Country
.
COUNTRY_UK
);
list
.
add
(
Country
.
COUNTRY_AT
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录