Skip to content

Commit e1a0625

Browse files
author
Keith Donald
committed
conversion service lookup in request
1 parent 315c16d commit e1a0625

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/EvalTag.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public int doEndTag() throws JspException {
9999
Expression expression = this.expressionParser.parseExpression(this.expression);
100100
EvaluationContext context = createEvaluationContext();
101101
if (this.var == null) {
102-
// print the url to the writer
103102
try {
104103
String result = expression.getValue(context, String.class);
105104
result = isHtmlEscape() ? HtmlUtils.htmlEscape(result) : result;
@@ -111,7 +110,6 @@ public int doEndTag() throws JspException {
111110
}
112111
}
113112
else {
114-
// store the url as a variable
115113
pageContext.setAttribute(var, expression.getValue(context), scope);
116114
}
117115
return EVAL_PAGE;
@@ -129,8 +127,7 @@ private EvaluationContext createEvaluationContext() {
129127

130128
private ConversionService getConversionService() {
131129
try {
132-
// TODO replace this with a call to RequestContext that is not brittle
133-
return getRequestContext().getWebApplicationContext().getBean("conversionService", ConversionService.class);
130+
return (ConversionService) this.pageContext.getRequest().getAttribute("org.springframework.core.convert.ConversionService");
134131
} catch (BeansException e) {
135132
return null;
136133
}

org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/AbstractTagTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import junit.framework.TestCase;
2020

21-
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
2221
import org.springframework.mock.web.MockHttpServletRequest;
2322
import org.springframework.mock.web.MockHttpServletResponse;
2423
import org.springframework.mock.web.MockPageContext;
@@ -44,8 +43,6 @@ protected MockPageContext createPageContext() {
4443
SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
4544
wac.setServletContext(sc);
4645
wac.setNamespace("test");
47-
// TODO this name index leads to brittle lookup by EvalTag
48-
wac.registerSingleton("conversionService", FormattingConversionServiceFactoryBean.class);
4946
wac.refresh();
5047

5148
MockHttpServletRequest request = new MockHttpServletRequest(sc);

org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/EvalTagTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.springframework.format.annotation.NumberFormat;
2424
import org.springframework.format.annotation.NumberFormat.Style;
25+
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
2526
import org.springframework.mock.web.MockHttpServletResponse;
2627
import org.springframework.mock.web.MockPageContext;
2728

@@ -33,6 +34,9 @@ public class EvalTagTests extends AbstractTagTests {
3334

3435
protected void setUp() throws Exception {
3536
context = createPageContext();
37+
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
38+
factory.afterPropertiesSet();
39+
context.getRequest().setAttribute("org.springframework.core.convert.ConversionService", factory.getObject());
3640
context.getRequest().setAttribute("bean", new Bean());
3741
tag = new EvalTag();
3842
tag.setPageContext(context);
@@ -53,7 +57,6 @@ public void testEndTagPrintFormattedScopedAttributeResult() throws Exception {
5357
assertEquals(Tag.EVAL_BODY_INCLUDE, action);
5458
action = tag.doEndTag();
5559
assertEquals(Tag.EVAL_PAGE, action);
56-
// TODO - fails because EL does not consider annotations on getter/setter method or field for properties (just annotations on method parameters)
5760
//assertEquals("25%", ((MockHttpServletResponse)context.getResponse()).getContentAsString());
5861
}
5962

0 commit comments

Comments
 (0)