JSP EvalTag resolves "@myBeanName" references in expressions against the WebApplicationContext (SPR-7312); for consistency, expressions in an ApplicationContext support the same syntax against the local BeanFactory
This commit is contained in:
@@ -19,11 +19,13 @@ package org.springframework.web.servlet.tags;
|
||||
import java.math.BigDecimal;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.format.annotation.NumberFormat;
|
||||
import org.springframework.format.annotation.NumberFormat.Style;
|
||||
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockPageContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
/**
|
||||
* @author Keith Donald
|
||||
@@ -103,6 +105,19 @@ public class EvalTagTests extends AbstractTagTests {
|
||||
assertEquals("not the bean object", context.getAttribute("foo"));
|
||||
}
|
||||
|
||||
public void testAccessUsingBeanSyntax() throws Exception {
|
||||
GenericApplicationContext wac = (GenericApplicationContext)
|
||||
context.getRequest().getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
|
||||
wac.getDefaultListableBeanFactory().registerSingleton("bean2", context.getRequest().getAttribute("bean"));
|
||||
tag.setExpression("@bean2.bean");
|
||||
tag.setVar("foo");
|
||||
int action = tag.doStartTag();
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, action);
|
||||
action = tag.doEndTag();
|
||||
assertEquals(Tag.EVAL_PAGE, action);
|
||||
assertEquals("not the bean object", context.getAttribute("foo"));
|
||||
}
|
||||
|
||||
|
||||
public static class Bean {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user