Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
564f0ec3
S
spring-framework
项目概览
dk131072
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
564f0ec3
编写于
6月 21, 2011
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-8444 Added MapAccessor and EnvironmentAccessor to EL context in the eval tag
上级
5f76ad80
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
0 deletion
+41
-0
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/EvalTag.java
...in/java/org/springframework/web/servlet/tags/EvalTag.java
+5
-0
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java
...va/org/springframework/web/servlet/tags/EvalTagTests.java
+36
-0
未找到文件。
org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/EvalTag.java
浏览文件 @
564f0ec3
...
...
@@ -17,11 +17,14 @@
package
org.springframework.web.servlet.tags
;
import
java.io.IOException
;
import
javax.servlet.jsp.JspException
;
import
javax.servlet.jsp.PageContext
;
import
javax.servlet.jsp.el.VariableResolver
;
import
org.springframework.context.expression.BeanFactoryResolver
;
import
org.springframework.context.expression.EnvironmentAccessor
;
import
org.springframework.context.expression.MapAccessor
;
import
org.springframework.core.convert.ConversionService
;
import
org.springframework.expression.AccessException
;
import
org.springframework.expression.EvaluationContext
;
...
...
@@ -135,6 +138,8 @@ public class EvalTag extends HtmlEscapingAwareTag {
private
EvaluationContext
createEvaluationContext
(
PageContext
pageContext
)
{
StandardEvaluationContext
context
=
new
StandardEvaluationContext
();
context
.
addPropertyAccessor
(
new
JspPropertyAccessor
(
pageContext
));
context
.
addPropertyAccessor
(
new
MapAccessor
());
context
.
addPropertyAccessor
(
new
EnvironmentAccessor
());
context
.
setBeanResolver
(
new
BeanFactoryResolver
(
getRequestContext
().
getWebApplicationContext
()));
ConversionService
conversionService
=
getConversionService
(
pageContext
);
if
(
conversionService
!=
null
)
{
...
...
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java
浏览文件 @
564f0ec3
...
...
@@ -17,9 +17,14 @@
package
org.springframework.web.servlet.tags
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.servlet.jsp.tagext.Tag
;
import
org.springframework.context.support.GenericApplicationContext
;
import
org.springframework.core.env.MapPropertySource
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.format.annotation.NumberFormat
;
import
org.springframework.format.annotation.NumberFormat.Style
;
import
org.springframework.format.support.FormattingConversionServiceFactoryBean
;
...
...
@@ -127,6 +132,31 @@ public class EvalTagTests extends AbstractTagTests {
assertEquals
(
"not the bean object"
,
context
.
getAttribute
(
"foo"
));
}
public
void
testEnvironmentAccess
()
throws
Exception
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"key.foo"
,
"value.foo"
);
GenericApplicationContext
wac
=
(
GenericApplicationContext
)
context
.
getRequest
().
getAttribute
(
DispatcherServlet
.
WEB_APPLICATION_CONTEXT_ATTRIBUTE
);
wac
.
getEnvironment
().
getPropertySources
().
addFirst
(
new
MapPropertySource
(
"mapSource"
,
map
));
wac
.
getDefaultListableBeanFactory
().
registerSingleton
(
"bean2"
,
context
.
getRequest
().
getAttribute
(
"bean"
));
tag
.
setExpression
(
"@environment['key.foo']"
);
int
action
=
tag
.
doStartTag
();
assertEquals
(
Tag
.
EVAL_BODY_INCLUDE
,
action
);
action
=
tag
.
doEndTag
();
assertEquals
(
Tag
.
EVAL_PAGE
,
action
);
assertEquals
(
"value.foo"
,
((
MockHttpServletResponse
)
context
.
getResponse
()).
getContentAsString
());
}
public
void
testMapAccess
()
throws
Exception
{
tag
.
setExpression
(
"bean.map.key"
);
int
action
=
tag
.
doStartTag
();
assertEquals
(
Tag
.
EVAL_BODY_INCLUDE
,
action
);
action
=
tag
.
doEndTag
();
assertEquals
(
Tag
.
EVAL_PAGE
,
action
);
assertEquals
(
"value"
,
((
MockHttpServletResponse
)
context
.
getResponse
()).
getContentAsString
());
}
public
static
class
Bean
{
...
...
@@ -154,6 +184,12 @@ public class EvalTagTests extends AbstractTagTests {
public
String
js
()
{
return
"function foo() { alert(\"hi\") }"
;
}
public
Map
<
String
,
Object
>
getMap
()
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"key"
,
"value"
);
return
map
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录