conversion service lookup in request
This commit is contained in:
parent
315c16de5f
commit
e1a0625a15
|
|
@ -99,7 +99,6 @@ public class EvalTag extends HtmlEscapingAwareTag {
|
||||||
Expression expression = this.expressionParser.parseExpression(this.expression);
|
Expression expression = this.expressionParser.parseExpression(this.expression);
|
||||||
EvaluationContext context = createEvaluationContext();
|
EvaluationContext context = createEvaluationContext();
|
||||||
if (this.var == null) {
|
if (this.var == null) {
|
||||||
// print the url to the writer
|
|
||||||
try {
|
try {
|
||||||
String result = expression.getValue(context, String.class);
|
String result = expression.getValue(context, String.class);
|
||||||
result = isHtmlEscape() ? HtmlUtils.htmlEscape(result) : result;
|
result = isHtmlEscape() ? HtmlUtils.htmlEscape(result) : result;
|
||||||
|
|
@ -111,7 +110,6 @@ public class EvalTag extends HtmlEscapingAwareTag {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// store the url as a variable
|
|
||||||
pageContext.setAttribute(var, expression.getValue(context), scope);
|
pageContext.setAttribute(var, expression.getValue(context), scope);
|
||||||
}
|
}
|
||||||
return EVAL_PAGE;
|
return EVAL_PAGE;
|
||||||
|
|
@ -129,8 +127,7 @@ public class EvalTag extends HtmlEscapingAwareTag {
|
||||||
|
|
||||||
private ConversionService getConversionService() {
|
private ConversionService getConversionService() {
|
||||||
try {
|
try {
|
||||||
// TODO replace this with a call to RequestContext that is not brittle
|
return (ConversionService) this.pageContext.getRequest().getAttribute("org.springframework.core.convert.ConversionService");
|
||||||
return getRequestContext().getWebApplicationContext().getBean("conversionService", ConversionService.class);
|
|
||||||
} catch (BeansException e) {
|
} catch (BeansException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package org.springframework.web.servlet.tags;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
|
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
import org.springframework.mock.web.MockPageContext;
|
import org.springframework.mock.web.MockPageContext;
|
||||||
|
|
@ -44,8 +43,6 @@ public abstract class AbstractTagTests extends TestCase {
|
||||||
SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
|
SimpleWebApplicationContext wac = new SimpleWebApplicationContext();
|
||||||
wac.setServletContext(sc);
|
wac.setServletContext(sc);
|
||||||
wac.setNamespace("test");
|
wac.setNamespace("test");
|
||||||
// TODO this name index leads to brittle lookup by EvalTag
|
|
||||||
wac.registerSingleton("conversionService", FormattingConversionServiceFactoryBean.class);
|
|
||||||
wac.refresh();
|
wac.refresh();
|
||||||
|
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest(sc);
|
MockHttpServletRequest request = new MockHttpServletRequest(sc);
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import javax.servlet.jsp.tagext.Tag;
|
||||||
|
|
||||||
import org.springframework.format.annotation.NumberFormat;
|
import org.springframework.format.annotation.NumberFormat;
|
||||||
import org.springframework.format.annotation.NumberFormat.Style;
|
import org.springframework.format.annotation.NumberFormat.Style;
|
||||||
|
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
import org.springframework.mock.web.MockPageContext;
|
import org.springframework.mock.web.MockPageContext;
|
||||||
|
|
||||||
|
|
@ -33,6 +34,9 @@ public class EvalTagTests extends AbstractTagTests {
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
context = createPageContext();
|
context = createPageContext();
|
||||||
|
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
|
||||||
|
factory.afterPropertiesSet();
|
||||||
|
context.getRequest().setAttribute("org.springframework.core.convert.ConversionService", factory.getObject());
|
||||||
context.getRequest().setAttribute("bean", new Bean());
|
context.getRequest().setAttribute("bean", new Bean());
|
||||||
tag = new EvalTag();
|
tag = new EvalTag();
|
||||||
tag.setPageContext(context);
|
tag.setPageContext(context);
|
||||||
|
|
@ -53,7 +57,6 @@ public class EvalTagTests extends AbstractTagTests {
|
||||||
assertEquals(Tag.EVAL_BODY_INCLUDE, action);
|
assertEquals(Tag.EVAL_BODY_INCLUDE, action);
|
||||||
action = tag.doEndTag();
|
action = tag.doEndTag();
|
||||||
assertEquals(Tag.EVAL_PAGE, action);
|
assertEquals(Tag.EVAL_PAGE, action);
|
||||||
// TODO - fails because EL does not consider annotations on getter/setter method or field for properties (just annotations on method parameters)
|
|
||||||
//assertEquals("25%", ((MockHttpServletResponse)context.getResponse()).getContentAsString());
|
//assertEquals("25%", ((MockHttpServletResponse)context.getResponse()).getContentAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue