diff --git a/spring-web/src/main/java/org/springframework/web/util/ExpressionEvaluationUtils.java b/spring-web/src/main/java/org/springframework/web/util/ExpressionEvaluationUtils.java deleted file mode 100644 index aaf93ba9884..00000000000 --- a/spring-web/src/main/java/org/springframework/web/util/ExpressionEvaluationUtils.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright 2002-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.util; - -import javax.servlet.ServletContext; -import javax.servlet.jsp.JspException; -import javax.servlet.jsp.PageContext; -import javax.servlet.jsp.el.ELException; - -import org.springframework.util.Assert; - -/** - * Convenience methods for accessing JSP 2.0's - * {@link javax.servlet.jsp.el.ExpressionEvaluator}. - * - *

The evaluation methods check if the value contains "${" before - * invoking the EL evaluator, treating the value as "normal" expression - * (i.e. a literal String value) else. - * - *

See {@link #isSpringJspExpressionSupportActive} for guidelines - * on when to use Spring's JSP expression support as opposed to the - * built-in expression support in JSP 2.0+ containers. - * - * @author Juergen Hoeller - * @author Alef Arendsen - * @since 11.07.2003 - * @see javax.servlet.jsp.el.ExpressionEvaluator#evaluate - * @deprecated as of Spring 3.2, in favor of the JSP 2.0+ native support - * for embedded expressions in JSP pages (also applying to tag attributes) - */ -@Deprecated -public abstract class ExpressionEvaluationUtils { - - /** - * Expression support parameter at the servlet context level - * (i.e. a context-param in {@code web.xml}): "springJspExpressionSupport". - */ - public static final String EXPRESSION_SUPPORT_CONTEXT_PARAM = "springJspExpressionSupport"; - - public static final String EXPRESSION_PREFIX = "${"; - - public static final String EXPRESSION_SUFFIX = "}"; - - - /** - * Check whether Spring's JSP expression support is actually active. - *

Note that JSP 2.0+ containers come with expression support themselves: - * However, it will only be active for web applications declaring Servlet 2.4 - * or higher in their {@code web.xml} deployment descriptor. - *

If a {@code web.xml} context-param named "springJspExpressionSupport" is - * found, its boolean value will be taken to decide whether this support is active. - * If not found, the default is for expression support to be inactive on Servlet 3.0 - * containers with web applications declaring Servlet 2.4 or higher in their - * {@code web.xml}. For backwards compatibility, Spring's expression support - * will remain active for applications declaring Servlet 2.3 or earlier. However, - * on Servlet 2.4/2.5 containers, we can't find out what the application has declared; - * as of Spring 3.2, we won't activate Spring's expression support at all then since - * it got deprecated and will be removed in the next iteration of the framework. - * @param pageContext current JSP PageContext - * @return {@code true} if active (ExpressionEvaluationUtils will actually evaluate expressions); - * {@code false} if not active (ExpressionEvaluationUtils will return given values as-is, - * relying on the JSP container pre-evaluating values before passing them to JSP tag attributes) - */ - public static boolean isSpringJspExpressionSupportActive(PageContext pageContext) { - ServletContext sc = pageContext.getServletContext(); - String springJspExpressionSupport = sc.getInitParameter(EXPRESSION_SUPPORT_CONTEXT_PARAM); - if (springJspExpressionSupport != null) { - return Boolean.valueOf(springJspExpressionSupport); - } - if (sc.getMajorVersion() >= 3) { - // We're on a Servlet 3.0+ container: Let's check what the application declares... - if (sc.getEffectiveMajorVersion() == 2 && sc.getEffectiveMinorVersion() < 4) { - // Application declares Servlet 2.3- in its web.xml: JSP 2.0 expressions not active. - // Activate our own expression support. - return true; - } - } - return false; - } - - /** - * Check if the given expression value is an EL expression. - * @param value the expression to check - * @return {@code true} if the expression is an EL expression, - * {@code false} otherwise - */ - public static boolean isExpressionLanguage(String value) { - return (value != null && value.contains(EXPRESSION_PREFIX)); - } - - /** - * Evaluate the given expression (be it EL or a literal String value) - * to an Object of a given type, - * @param attrName name of the attribute (typically a JSP tag attribute) - * @param attrValue value of the attribute - * @param resultClass class that the result should have (String, Integer, Boolean) - * @param pageContext current JSP PageContext - * @return the result of the evaluation - * @throws JspException in case of parsing errors, also in case of type mismatch - * if the passed-in literal value is not an EL expression and not assignable to - * the result class - */ - public static Object evaluate(String attrName, String attrValue, Class resultClass, PageContext pageContext) - throws JspException { - - if (isSpringJspExpressionSupportActive(pageContext) && isExpressionLanguage(attrValue)) { - return doEvaluate(attrName, attrValue, resultClass, pageContext); - } - else if (attrValue != null && resultClass != null && !resultClass.isInstance(attrValue)) { - throw new JspException("Attribute value \"" + attrValue + "\" is neither a JSP EL expression nor " + - "assignable to result class [" + resultClass.getName() + "]"); - } - else { - return attrValue; - } - } - - /** - * Evaluate the given expression (be it EL or a literal String value) to an Object. - * @param attrName name of the attribute (typically a JSP tag attribute) - * @param attrValue value of the attribute - * @param pageContext current JSP PageContext - * @return the result of the evaluation - * @throws JspException in case of parsing errors - */ - public static Object evaluate(String attrName, String attrValue, PageContext pageContext) - throws JspException { - - if (isSpringJspExpressionSupportActive(pageContext) && isExpressionLanguage(attrValue)) { - return doEvaluate(attrName, attrValue, Object.class, pageContext); - } - else { - return attrValue; - } - } - - /** - * Evaluate the given expression (be it EL or a literal String value) to a String. - * @param attrName name of the attribute (typically a JSP tag attribute) - * @param attrValue value of the attribute - * @param pageContext current JSP PageContext - * @return the result of the evaluation - * @throws JspException in case of parsing errors - */ - public static String evaluateString(String attrName, String attrValue, PageContext pageContext) - throws JspException { - - if (isSpringJspExpressionSupportActive(pageContext) && isExpressionLanguage(attrValue)) { - return (String) doEvaluate(attrName, attrValue, String.class, pageContext); - } - else { - return attrValue; - } - } - - /** - * Evaluate the given expression (be it EL or a literal String value) to an integer. - * @param attrName name of the attribute (typically a JSP tag attribute) - * @param attrValue value of the attribute - * @param pageContext current JSP PageContext - * @return the result of the evaluation - * @throws JspException in case of parsing errors - */ - public static int evaluateInteger(String attrName, String attrValue, PageContext pageContext) - throws JspException { - - if (isSpringJspExpressionSupportActive(pageContext) && isExpressionLanguage(attrValue)) { - return (Integer) doEvaluate(attrName, attrValue, Integer.class, pageContext); - } - else { - return Integer.parseInt(attrValue); - } - } - - /** - * Evaluate the given expression (be it EL or a literal String value) to a boolean. - * @param attrName name of the attribute (typically a JSP tag attribute) - * @param attrValue value of the attribute - * @param pageContext current JSP PageContext - * @return the result of the evaluation - * @throws JspException in case of parsing errors - */ - public static boolean evaluateBoolean(String attrName, String attrValue, PageContext pageContext) - throws JspException { - - if (isSpringJspExpressionSupportActive(pageContext) && isExpressionLanguage(attrValue)) { - return (Boolean) doEvaluate(attrName, attrValue, Boolean.class, pageContext); - } - else { - return Boolean.valueOf(attrValue); - } - } - - /** - * Actually evaluate the given expression (be it EL or a literal String value) - * to an Object of a given type. Supports concatenated expressions, - * for example: "${var1}text${var2}" - * @param attrName name of the attribute - * @param attrValue value of the attribute - * @param resultClass class that the result should have - * @param pageContext current JSP PageContext - * @return the result of the evaluation - * @throws JspException in case of parsing errors - */ - private static Object doEvaluate(String attrName, String attrValue, Class resultClass, PageContext pageContext) - throws JspException { - - Assert.notNull(attrValue, "Attribute value must not be null"); - Assert.notNull(resultClass, "Result class must not be null"); - Assert.notNull(pageContext, "PageContext must not be null"); - - try { - if (resultClass.isAssignableFrom(String.class)) { - StringBuilder resultValue = null; - int exprPrefixIndex; - int exprSuffixIndex = 0; - do { - exprPrefixIndex = attrValue.indexOf(EXPRESSION_PREFIX, exprSuffixIndex); - if (exprPrefixIndex != -1) { - int prevExprSuffixIndex = exprSuffixIndex; - exprSuffixIndex = attrValue.indexOf(EXPRESSION_SUFFIX, exprPrefixIndex + EXPRESSION_PREFIX.length()); - String expr; - if (exprSuffixIndex != -1) { - exprSuffixIndex += EXPRESSION_SUFFIX.length(); - expr = attrValue.substring(exprPrefixIndex, exprSuffixIndex); - } - else { - expr = attrValue.substring(exprPrefixIndex); - } - if (expr.length() == attrValue.length()) { - // A single expression without static prefix or suffix -> - // parse it with the specified result class rather than String. - return evaluateExpression(attrValue, resultClass, pageContext); - } - else { - // We actually need to concatenate partial expressions into a String. - if (resultValue == null) { - resultValue = new StringBuilder(); - } - resultValue.append(attrValue.substring(prevExprSuffixIndex, exprPrefixIndex)); - resultValue.append(evaluateExpression(expr, String.class, pageContext)); - } - } - else { - if (resultValue == null) { - resultValue = new StringBuilder(); - } - resultValue.append(attrValue.substring(exprSuffixIndex)); - } - } - while (exprPrefixIndex != -1 && exprSuffixIndex != -1); - return resultValue.toString(); - } - else { - return evaluateExpression(attrValue, resultClass, pageContext); - } - } - catch (ELException ex) { - throw new JspException("Parsing of JSP EL expression failed for attribute '" + attrName + "'", ex); - } - } - - private static Object evaluateExpression(String exprValue, Class resultClass, PageContext pageContext) - throws ELException { - - return pageContext.getExpressionEvaluator().evaluate( - exprValue, resultClass, pageContext.getVariableResolver(), null); - } - -} diff --git a/spring-web/src/test/java/org/springframework/web/util/ExpressionEvaluationUtilsTests.java b/spring-web/src/test/java/org/springframework/web/util/ExpressionEvaluationUtilsTests.java deleted file mode 100644 index 8da5c1adb3a..00000000000 --- a/spring-web/src/test/java/org/springframework/web/util/ExpressionEvaluationUtilsTests.java +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Copyright 2002-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.util; - -import javax.servlet.ServletContext; -import javax.servlet.jsp.JspException; -import javax.servlet.jsp.PageContext; -import javax.servlet.jsp.el.ELException; -import javax.servlet.jsp.el.Expression; -import javax.servlet.jsp.el.ExpressionEvaluator; -import javax.servlet.jsp.el.FunctionMapper; -import javax.servlet.jsp.el.VariableResolver; - -import org.junit.Test; - -import org.springframework.mock.web.test.MockExpressionEvaluator; -import org.springframework.mock.web.test.MockPageContext; -import org.springframework.mock.web.test.MockServletContext; - -import static org.junit.Assert.*; - -/** - * @author Alef Arendsen - * @author Juergen Hoeller - * @since 16.09.2003 - */ -@Deprecated -public class ExpressionEvaluationUtilsTests { - - @Test - public void testIsSpringJspExpressionSupportActive() { - MockServletContext sc = new MockServletContext(); - PageContext pc = new MockPageContext(sc); - assertFalse(ExpressionEvaluationUtils.isSpringJspExpressionSupportActive(pc)); - sc.addInitParameter("springJspExpressionSupport", "true"); - assertTrue(ExpressionEvaluationUtils.isSpringJspExpressionSupportActive(pc)); - } - - @Test - public void testIsSpringJspExpressionSupportActiveOnServlet30() { - MockServletContext sc = new MockServletContext(); - sc.setMajorVersion(3); - sc.setMinorVersion(0); - PageContext pc = new MockPageContext(sc); - assertFalse(ExpressionEvaluationUtils.isSpringJspExpressionSupportActive(pc)); - sc.addInitParameter("springJspExpressionSupport", "true"); - assertTrue(ExpressionEvaluationUtils.isSpringJspExpressionSupportActive(pc)); - } - - @Test - public void testIsSpringJspExpressionSupportActiveOnServlet30WithServlet23Application() { - MockServletContext sc = new MockServletContext(); - sc.setMajorVersion(3); - sc.setMinorVersion(0); - sc.setEffectiveMajorVersion(2); - sc.setEffectiveMinorVersion(3); - PageContext pc = new MockPageContext(sc); - assertTrue(ExpressionEvaluationUtils.isSpringJspExpressionSupportActive(pc)); - sc.addInitParameter("springJspExpressionSupport", "false"); - assertFalse(ExpressionEvaluationUtils.isSpringJspExpressionSupportActive(pc)); - } - - @Test - public void testIsExpressionLanguage() { - assertTrue(ExpressionEvaluationUtils.isExpressionLanguage("${bla}")); - assertTrue(ExpressionEvaluationUtils.isExpressionLanguage("bla${bla}")); - assertFalse(ExpressionEvaluationUtils.isExpressionLanguage("bla{bla")); - assertFalse(ExpressionEvaluationUtils.isExpressionLanguage("bla$b{")); - } - - @Test - public void testEvaluate() throws Exception { - MockServletContext sc = new MockServletContext(); - sc.addInitParameter("springJspExpressionSupport", "true"); - MockPageContext ctx = new MockPageContext(sc); - ctx.setAttribute("bla", "blie"); - - assertEquals("blie", ExpressionEvaluationUtils.evaluate("test", "${bla}", String.class, ctx)); - assertEquals("test", ExpressionEvaluationUtils.evaluate("test", "test", String.class, ctx)); - - try { - ExpressionEvaluationUtils.evaluate("test", "test", Float.class, ctx); - fail("Should have thrown JspException"); - } - catch (JspException ex) { - // expected - } - } - - @Test - public void testEvaluateWithConcatenation() throws Exception { - MockServletContext sc = new MockServletContext(); - sc.addInitParameter("springJspExpressionSupport", "true"); - MockPageContext ctx = new MockPageContext(sc); - ctx.setAttribute("bla", "blie"); - - String expr = "text${bla}text${bla}text"; - Object o = ExpressionEvaluationUtils.evaluate("test", expr, String.class, ctx); - assertEquals("textblietextblietext", o); - - expr = "${bla}text${bla}text"; - o = ExpressionEvaluationUtils.evaluate("test", expr, String.class, ctx); - assertEquals("blietextblietext", o); - - expr = "${bla}text${bla}"; - o = ExpressionEvaluationUtils.evaluate("test", expr, String.class, ctx); - assertEquals("blietextblie", o); - - expr = "${bla}text${bla}"; - o = ExpressionEvaluationUtils.evaluate("test", expr, Object.class, ctx); - assertEquals("blietextblie", o); - - try { - expr = "${bla}text${bla"; - ExpressionEvaluationUtils.evaluate("test", expr, Object.class, ctx); - fail("Should have thrown JspException"); - } - catch (JspException ex) { - // expected - } - - try { - expr = "${bla}text${bla}"; - ExpressionEvaluationUtils.evaluate("test", expr, Float.class, ctx); - fail("Should have thrown JspException"); - } - catch (JspException ex) { - // expected - } - } - - @Test - public void testEvaluateString() throws Exception { - MockServletContext sc = new MockServletContext(); - sc.addInitParameter("springJspExpressionSupport", "true"); - MockPageContext ctx = new MockPageContext(sc); - ctx.setAttribute("bla", "blie"); - - assertEquals("blie", ExpressionEvaluationUtils.evaluateString("test", "${bla}", ctx)); - assertEquals("blie", ExpressionEvaluationUtils.evaluateString("test", "blie", ctx)); - } - - @Test - public void testEvaluateStringWithConcatenation() throws Exception { - MockServletContext sc = new MockServletContext(); - sc.addInitParameter("springJspExpressionSupport", "true"); - MockPageContext ctx = new MockPageContext(sc); - ctx.setAttribute("bla", "blie"); - - String expr = "text${bla}text${bla}text"; - String s = ExpressionEvaluationUtils.evaluateString("test", expr, ctx); - assertEquals("textblietextblietext", s); - - expr = "${bla}text${bla}text"; - s = ExpressionEvaluationUtils.evaluateString("test", expr, ctx); - assertEquals("blietextblietext", s); - - expr = "${bla}text${bla}"; - s = ExpressionEvaluationUtils.evaluateString("test", expr, ctx); - assertEquals("blietextblie", s); - - expr = "${bla}text${bla}"; - s = ExpressionEvaluationUtils.evaluateString("test", expr, ctx); - assertEquals("blietextblie", s); - - try { - expr = "${bla}text${bla"; - ExpressionEvaluationUtils.evaluateString("test", expr, ctx); - fail("Should have thrown JspException"); - } - catch (JspException ex) { - // expected - } - - } - - @Test - public void testEvaluateInteger() throws Exception { - MockServletContext sc = new MockServletContext(); - sc.addInitParameter("springJspExpressionSupport", "true"); - MockPageContext ctx = new MockPageContext(sc); - ctx.setAttribute("bla", new Integer(1)); - - assertEquals(1, ExpressionEvaluationUtils.evaluateInteger("test", "${bla}", ctx)); - assertEquals(21, ExpressionEvaluationUtils.evaluateInteger("test", "21", ctx)); - } - - @Test - public void testEvaluateBoolean() throws Exception { - MockServletContext sc = new MockServletContext(); - sc.addInitParameter("springJspExpressionSupport", "true"); - MockPageContext ctx = new MockPageContext(sc); - ctx.setAttribute("bla", new Boolean(true)); - - assertTrue(ExpressionEvaluationUtils.evaluateBoolean("test", "${bla}", ctx)); - assertTrue(ExpressionEvaluationUtils.evaluateBoolean("test", "true", ctx)); - } - - @Test - public void testRepeatedEvaluate() throws Exception { - MockServletContext sc = new MockServletContext(); - sc.addInitParameter("springJspExpressionSupport", "true"); - PageContext ctx = new CountingMockPageContext(sc); - CountingMockExpressionEvaluator eval = (CountingMockExpressionEvaluator) ctx.getExpressionEvaluator(); - ctx.setAttribute("bla", "blie"); - ctx.setAttribute("blo", "blue"); - - assertEquals("blie", ExpressionEvaluationUtils.evaluate("test", "${bla}", String.class, ctx)); - assertEquals(1, eval.evaluateCount); - - assertEquals("blue", ExpressionEvaluationUtils.evaluate("test", "${blo}", String.class, ctx)); - assertEquals(2, eval.evaluateCount); - - assertEquals("blie", ExpressionEvaluationUtils.evaluate("test", "${bla}", String.class, ctx)); - assertEquals(3, eval.evaluateCount); - - assertEquals("blue", ExpressionEvaluationUtils.evaluate("test", "${blo}", String.class, ctx)); - assertEquals(4, eval.evaluateCount); - } - - @Test - public void testEvaluateWithComplexConcatenation() throws Exception { - MockServletContext sc = new MockServletContext(); - sc.addInitParameter("springJspExpressionSupport", "true"); - PageContext ctx = new CountingMockPageContext(sc); - CountingMockExpressionEvaluator eval = (CountingMockExpressionEvaluator) ctx.getExpressionEvaluator(); - ctx.setAttribute("bla", "blie"); - ctx.setAttribute("blo", "blue"); - - String expr = "text${bla}text${blo}text"; - Object o = ExpressionEvaluationUtils.evaluate("test", expr, String.class, ctx); - assertEquals("textblietextbluetext", o); - assertEquals(2, eval.evaluateCount); - - expr = "${bla}text${blo}text"; - o = ExpressionEvaluationUtils.evaluate("test", expr, String.class, ctx); - assertEquals("blietextbluetext", o); - assertEquals(4, eval.evaluateCount); - - expr = "${bla}text${blo}"; - o = ExpressionEvaluationUtils.evaluate("test", expr, String.class, ctx); - assertEquals("blietextblue", o); - assertEquals(6, eval.evaluateCount); - - expr = "${bla}text${blo}"; - o = ExpressionEvaluationUtils.evaluate("test", expr, Object.class, ctx); - assertEquals("blietextblue", o); - assertEquals(8, eval.evaluateCount); - } - - - private static class CountingMockPageContext extends MockPageContext { - - public CountingMockPageContext(ServletContext servletContext) { - super(servletContext); - } - - private ExpressionEvaluator eval = new CountingMockExpressionEvaluator(this); - - @Override - public ExpressionEvaluator getExpressionEvaluator() { - return eval; - } - } - - - private static class CountingMockExpressionEvaluator extends MockExpressionEvaluator { - - public int parseExpressionCount = 0; - - public int evaluateCount = 0; - - public CountingMockExpressionEvaluator(PageContext pageContext) { - super(pageContext); - } - - @Override - public Expression parseExpression(String expression, Class expectedType, FunctionMapper functionMapper) throws ELException { - this.parseExpressionCount++; - return super.parseExpression(expression, expectedType, functionMapper); - } - - @Override - public Object evaluate(String expression, Class expectedType, VariableResolver variableResolver, FunctionMapper functionMapper) throws ELException { - this.evaluateCount++; - return super.evaluate(expression, expectedType, variableResolver, functionMapper); - } - } - -} diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindErrorsTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindErrorsTag.java index cf037fc1158..666a334b308 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindErrorsTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindErrorsTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -21,7 +21,6 @@ import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import org.springframework.validation.Errors; -import org.springframework.web.util.ExpressionEvaluationUtils; /** * JSP tag that evaluates content if there are binding errors @@ -61,9 +60,7 @@ public class BindErrorsTag extends HtmlEscapingAwareTag { @Override protected final int doStartTagInternal() throws ServletException, JspException { - String resolvedName = ExpressionEvaluationUtils.evaluateString("name", this.name, pageContext); - this.errors = getRequestContext().getErrors(resolvedName, isHtmlEscape()); - + this.errors = getRequestContext().getErrors(this.name, isHtmlEscape()); if (this.errors != null && this.errors.hasErrors()) { this.pageContext.setAttribute(ERRORS_VARIABLE_NAME, this.errors, PageContext.REQUEST_SCOPE); return EVAL_BODY_INCLUDE; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindTag.java index f5b45233e11..3f060693412 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -17,13 +17,11 @@ package org.springframework.web.servlet.tags; import java.beans.PropertyEditor; - import javax.servlet.jsp.JspTagException; import javax.servlet.jsp.PageContext; import org.springframework.validation.Errors; import org.springframework.web.servlet.support.BindStatus; -import org.springframework.web.util.ExpressionEvaluationUtils; /** * Bind tag, supporting evaluation of binding errors for a certain @@ -104,8 +102,7 @@ public class BindTag extends HtmlEscapingAwareTag implements EditorAwareTag { @Override protected final int doStartTagInternal() throws Exception { - String resolvedPath = ExpressionEvaluationUtils.evaluateString("path", getPath(), pageContext); - + String resolvedPath = getPath(); if (!isIgnoreNestedPath()) { String nestedPath = (String) pageContext.getAttribute( NestedPathTag.NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java index 2c0056def49..0102f23bc91 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -17,12 +17,10 @@ package org.springframework.web.servlet.tags; import java.io.IOException; - import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.BodyContent; import javax.servlet.jsp.tagext.BodyTag; -import org.springframework.web.util.ExpressionEvaluationUtils; import org.springframework.web.util.HtmlUtils; import org.springframework.web.util.JavaScriptUtils; @@ -55,9 +53,8 @@ public class EscapeBodyTag extends HtmlEscapingAwareTag implements BodyTag { * Set JavaScript escaping for this tag, as boolean value. * Default is "false". */ - public void setJavaScriptEscape(String javaScriptEscape) throws JspException { - this.javaScriptEscape = - ExpressionEvaluationUtils.evaluateBoolean("javaScriptEscape", javaScriptEscape, pageContext); + public void setJavaScriptEscape(boolean javaScriptEscape) throws JspException { + this.javaScriptEscape = javaScriptEscape; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java index 6ec63b58c8d..391935eb53b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -17,7 +17,6 @@ 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; @@ -36,7 +35,6 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardTypeConverter; import org.springframework.util.ObjectUtils; -import org.springframework.web.util.ExpressionEvaluationUtils; import org.springframework.web.util.HtmlUtils; import org.springframework.web.util.JavaScriptUtils; import org.springframework.web.util.TagUtils; @@ -98,9 +96,8 @@ public class EvalTag extends HtmlEscapingAwareTag { * Set JavaScript escaping for this tag, as boolean value. * Default is "false". */ - public void setJavaScriptEscape(String javaScriptEscape) throws JspException { - this.javaScriptEscape = - ExpressionEvaluationUtils.evaluateBoolean("javaScriptEscape", javaScriptEscape, this.pageContext); + public void setJavaScriptEscape(boolean javaScriptEscape) throws JspException { + this.javaScriptEscape = javaScriptEscape; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapeTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapeTag.java index 8e610458101..4262f865a6b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapeTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapeTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,8 +18,6 @@ package org.springframework.web.servlet.tags; import javax.servlet.jsp.JspException; -import org.springframework.web.util.ExpressionEvaluationUtils; - /** * Sets default HTML escape value for the current page. The actual value * can be overridden by escaping-aware tags. The default is "false". @@ -34,23 +32,21 @@ import org.springframework.web.util.ExpressionEvaluationUtils; @SuppressWarnings("serial") public class HtmlEscapeTag extends RequestContextAwareTag { - private String defaultHtmlEscape; + private boolean defaultHtmlEscape; /** * Set the default value for HTML escaping, * to be put into the current PageContext. */ - public void setDefaultHtmlEscape(String defaultHtmlEscape) { + public void setDefaultHtmlEscape(boolean defaultHtmlEscape) { this.defaultHtmlEscape = defaultHtmlEscape; } @Override protected int doStartTagInternal() throws JspException { - boolean resolvedDefaultHtmlEscape = - ExpressionEvaluationUtils.evaluateBoolean("defaultHtmlEscape", this.defaultHtmlEscape, pageContext); - getRequestContext().setDefaultHtmlEscape(resolvedDefaultHtmlEscape); + getRequestContext().setDefaultHtmlEscape(this.defaultHtmlEscape); return EVAL_BODY_INCLUDE; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapingAwareTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapingAwareTag.java index 05db5eb70a3..862d57c1a38 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapingAwareTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapingAwareTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,8 +18,6 @@ package org.springframework.web.servlet.tags; import javax.servlet.jsp.JspException; -import org.springframework.web.util.ExpressionEvaluationUtils; - /** * Superclass for tags that output content that might get HTML-escaped. * @@ -46,8 +44,8 @@ public abstract class HtmlEscapingAwareTag extends RequestContextAwareTag { * Overrides the default HTML escaping setting for the current page. * @see HtmlEscapeTag#setDefaultHtmlEscape */ - public void setHtmlEscape(String htmlEscape) throws JspException { - this.htmlEscape = ExpressionEvaluationUtils.evaluateBoolean("htmlEscape", htmlEscape, pageContext); + public void setHtmlEscape(boolean htmlEscape) throws JspException { + this.htmlEscape = htmlEscape; } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java index a3a0c4c7f50..a861da494be 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,7 +18,6 @@ package org.springframework.web.servlet.tags; import java.io.IOException; import java.util.Collection; - import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspTagException; @@ -27,7 +26,6 @@ import org.springframework.context.MessageSourceResolvable; import org.springframework.context.NoSuchMessageException; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; -import org.springframework.web.util.ExpressionEvaluationUtils; import org.springframework.web.util.HtmlUtils; import org.springframework.web.util.JavaScriptUtils; import org.springframework.web.util.TagUtils; @@ -60,7 +58,7 @@ public class MessageTag extends HtmlEscapingAwareTag { public static final String DEFAULT_ARGUMENT_SEPARATOR = ","; - private Object message; + private MessageSourceResolvable message; private String code; @@ -79,12 +77,10 @@ public class MessageTag extends HtmlEscapingAwareTag { /** * Set the MessageSourceResolvable for this tag. - * Accepts a direct MessageSourceResolvable instance as well as a JSP - * expression language String that points to a MessageSourceResolvable. *

If a MessageSourceResolvable is specified, it effectively overrides * any code, arguments or text specified on this tag. */ - public void setMessage(Object message) { + public void setMessage(MessageSourceResolvable message) { this.message = message; } @@ -145,9 +141,8 @@ public class MessageTag extends HtmlEscapingAwareTag { * Set JavaScript escaping for this tag, as boolean value. * Default is "false". */ - public void setJavaScriptEscape(String javaScriptEscape) throws JspException { - this.javaScriptEscape = - ExpressionEvaluationUtils.evaluateBoolean("javaScriptEscape", javaScriptEscape, pageContext); + public void setJavaScriptEscape(boolean javaScriptEscape) throws JspException { + this.javaScriptEscape = javaScriptEscape; } @@ -170,10 +165,8 @@ public class MessageTag extends HtmlEscapingAwareTag { msg = this.javaScriptEscape ? JavaScriptUtils.javaScriptEscape(msg) : msg; // Expose as variable, if demanded, else write to the page. - String resolvedVar = ExpressionEvaluationUtils.evaluateString("var", this.var, pageContext); - if (resolvedVar != null) { - String resolvedScope = ExpressionEvaluationUtils.evaluateString("scope", this.scope, pageContext); - pageContext.setAttribute(resolvedVar, msg, TagUtils.getScope(resolvedScope)); + if (this.var != null) { + pageContext.setAttribute(this.var, msg, TagUtils.getScope(this.scope)); } else { writeMessage(msg); @@ -197,41 +190,28 @@ public class MessageTag extends HtmlEscapingAwareTag { } // Evaluate the specified MessageSourceResolvable, if any. - MessageSourceResolvable resolvedMessage = null; - if (this.message instanceof MessageSourceResolvable) { - resolvedMessage = (MessageSourceResolvable) this.message; - } - else if (this.message != null) { - String expr = this.message.toString(); - resolvedMessage = (MessageSourceResolvable) - ExpressionEvaluationUtils.evaluate("message", expr, MessageSourceResolvable.class, pageContext); - } - - if (resolvedMessage != null) { + if (this.message != null) { // We have a given MessageSourceResolvable. - return messageSource.getMessage(resolvedMessage, getRequestContext().getLocale()); + return messageSource.getMessage(this.message, getRequestContext().getLocale()); } - String resolvedCode = ExpressionEvaluationUtils.evaluateString("code", this.code, pageContext); - String resolvedText = ExpressionEvaluationUtils.evaluateString("text", this.text, pageContext); - - if (resolvedCode != null || resolvedText != null) { + if (this.code != null || this.text != null) { // We have a code or default text that we need to resolve. Object[] argumentsArray = resolveArguments(this.arguments); - if (resolvedText != null) { + if (this.text != null) { // We have a fallback text to consider. return messageSource.getMessage( - resolvedCode, argumentsArray, resolvedText, getRequestContext().getLocale()); + this.code, argumentsArray, this.text, getRequestContext().getLocale()); } else { // We have no fallback text to consider. return messageSource.getMessage( - resolvedCode, argumentsArray, getRequestContext().getLocale()); + this.code, argumentsArray, getRequestContext().getLocale()); } } // All we have is a specified literal text. - return resolvedText; + return this.text; } /** @@ -246,7 +226,7 @@ public class MessageTag extends HtmlEscapingAwareTag { String[] stringArray = StringUtils.delimitedListToStringArray((String) arguments, this.argumentSeparator); if (stringArray.length == 1) { - Object argument = ExpressionEvaluationUtils.evaluate("argument", stringArray[0], pageContext); + Object argument = stringArray[0]; if (argument != null && argument.getClass().isArray()) { return ObjectUtils.toObjectArray(argument); } @@ -255,12 +235,7 @@ public class MessageTag extends HtmlEscapingAwareTag { } } else { - Object[] argumentsArray = new Object[stringArray.length]; - for (int i = 0; i < stringArray.length; i++) { - argumentsArray[i] = - ExpressionEvaluationUtils.evaluate("argument[" + i + "]", stringArray[i], pageContext); - } - return argumentsArray; + return stringArray; } } else if (arguments instanceof Object[]) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java index 1f8ddd28432..6f9222a8704 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java @@ -22,7 +22,6 @@ import javax.servlet.jsp.tagext.TagSupport; import javax.servlet.jsp.tagext.TryCatchFinally; import org.springframework.beans.PropertyAccessor; -import org.springframework.web.util.ExpressionEvaluationUtils; /** *

Nested-path tag, to support and assist with nested beans or bean properties @@ -81,14 +80,12 @@ public class NestedPathTag extends TagSupport implements TryCatchFinally { @Override public int doStartTag() throws JspException { - String resolvedPath = ExpressionEvaluationUtils.evaluateString("path", getPath(), pageContext); - // Save previous nestedPath value, build and expose current nestedPath value. // Use request scope to expose nestedPath to included pages too. this.previousNestedPath = (String) pageContext.getAttribute(NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE); String nestedPath = - (this.previousNestedPath != null ? this.previousNestedPath + resolvedPath : resolvedPath); + (this.previousNestedPath != null ? this.previousNestedPath + getPath() : getPath()); pageContext.setAttribute(NESTED_PATH_VARIABLE_NAME, nestedPath, PageContext.REQUEST_SCOPE); return EVAL_BODY_INCLUDE; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/TransformTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/TransformTag.java index a0379d88000..58a90417030 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/TransformTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/TransformTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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,11 +18,9 @@ package org.springframework.web.servlet.tags; import java.beans.PropertyEditor; import java.io.IOException; - import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.TagSupport; -import org.springframework.web.util.ExpressionEvaluationUtils; import org.springframework.web.util.HtmlUtils; import org.springframework.web.util.TagUtils; @@ -32,7 +30,7 @@ import org.springframework.web.util.TagUtils; * form element tag from Spring's form tag library). * *

The BindTag has a PropertyEditor that it uses to transform properties of - * a bean to a String, useable in HTML forms. This tag uses that PropertyEditor + * a bean to a String, usable in HTML forms. This tag uses that PropertyEditor * to transform objects passed into this tag. * * @author Alef Arendsen @@ -59,11 +57,6 @@ public class TransformTag extends HtmlEscapingAwareTag { *

The value can either be a plain value to transform (a hard-coded String * value in a JSP or a JSP expression), or a JSP EL expression to be evaluated * (transforming the result of the expression). - *

Like all of Spring's JSP tags, this tag is capable of parsing EL expressions - * itself, on any JSP version. Note, however, that EL expressions in a JSP 2.0 page - * will be evaluated by the JSP container, with the result getting passed in here. - * For this reason, the type of this property is Object (accepting any result - * object from a pre-evaluated expression) rather than String. */ public void setValue(Object value) { this.value = value; @@ -93,13 +86,7 @@ public class TransformTag extends HtmlEscapingAwareTag { @Override protected final int doStartTagInternal() throws JspException { - Object resolvedValue = this.value; - if (this.value instanceof String) { - String strValue = (String) this.value; - resolvedValue = ExpressionEvaluationUtils.evaluate("value", strValue, pageContext); - } - - if (resolvedValue != null) { + if (this.value != null) { // Find the containing EditorAwareTag (e.g. BindTag), if applicable. EditorAwareTag tag = (EditorAwareTag) TagSupport.findAncestorWithClass(this, EditorAwareTag.class); if (tag == null) { @@ -111,18 +98,16 @@ public class TransformTag extends HtmlEscapingAwareTag { PropertyEditor editor = tag.getEditor(); if (editor != null) { // If an editor was found, edit the value. - editor.setValue(resolvedValue); + editor.setValue(this.value); result = editor.getAsText(); } else { // Else, just do a toString. - result = resolvedValue.toString(); + result = this.value.toString(); } result = isHtmlEscape() ? HtmlUtils.htmlEscape(result) : result; - String resolvedVar = ExpressionEvaluationUtils.evaluateString("var", this.var, pageContext); - if (resolvedVar != null) { - String resolvedScope = ExpressionEvaluationUtils.evaluateString("scope", this.scope, pageContext); - pageContext.setAttribute(resolvedVar, result, TagUtils.getScope(resolvedScope)); + if (this.var != null) { + pageContext.setAttribute(this.var, result, TagUtils.getScope(this.scope)); } else { try { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java index 370bf196882..d702e14f283 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -22,7 +22,6 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; - import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -31,7 +30,6 @@ import javax.servlet.jsp.PageContext; import org.springframework.util.StringUtils; import org.springframework.web.servlet.support.RequestDataValueProcessor; -import org.springframework.web.util.ExpressionEvaluationUtils; import org.springframework.web.util.HtmlUtils; import org.springframework.web.util.JavaScriptUtils; import org.springframework.web.util.TagUtils; @@ -152,9 +150,8 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware { * Set JavaScript escaping for this tag, as boolean value. * Default is "false". */ - public void setJavaScriptEscape(String javaScriptEscape) throws JspException { - this.javaScriptEscape = - ExpressionEvaluationUtils.evaluateBoolean("javaScriptEscape", javaScriptEscape, pageContext); + public void setJavaScriptEscape(boolean javaScriptEscape) throws JspException { + this.javaScriptEscape = javaScriptEscape; } public void addParam(Param param) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractFormTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractFormTag.java index 67f62f3d368..8227f35353c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractFormTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractFormTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -21,7 +21,6 @@ import javax.servlet.jsp.JspException; import org.springframework.util.ObjectUtils; import org.springframework.web.servlet.tags.HtmlEscapingAwareTag; -import org.springframework.web.util.ExpressionEvaluationUtils; /** * Base class for all JSP form tags. Provides utility methods for @@ -42,29 +41,11 @@ import org.springframework.web.util.ExpressionEvaluationUtils; public abstract class AbstractFormTag extends HtmlEscapingAwareTag { /** - * Evaluate the supplied value for the supplied attribute name. If the supplied value - * is {@code null} then {@code null} is returned, otherwise evaluation is - * handled using {@link ExpressionEvaluationUtils#evaluate(String, String, javax.servlet.jsp.PageContext)}. + * Evaluate the supplied value for the supplied attribute name. + *

The default implementation simply returns the given value as-is. */ protected Object evaluate(String attributeName, Object value) throws JspException { - if (value instanceof String) { - return ExpressionEvaluationUtils.evaluate(attributeName, (String) value, this.pageContext); - } - else { - return value; - } - } - - /** - * Evaluate the supplied value for the supplied attribute name. If the supplied value - * is {@code null} then {@code false} is returned, otherwise evaluation is - * handled using {@link ExpressionEvaluationUtils#evaluate(String, String, javax.servlet.jsp.PageContext)}, - * with subsequent matching against {@code Boolean.TRUE} and {@code Boolean.valueOf}. - */ - protected boolean evaluateBoolean(String attributeName, String value) throws JspException { - Object evaluated = ExpressionEvaluationUtils.evaluate(attributeName, value, this.pageContext); - return (Boolean.TRUE.equals(evaluated) || - (evaluated instanceof String && Boolean.valueOf((String) evaluated))); + return value; } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlInputElementTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlInputElementTag.java index 1718b08feaf..90e94823aa8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlInputElementTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlInputElementTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -71,9 +71,9 @@ public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag private String accesskey; - private String disabled; + private boolean disabled; - private String readonly; + private boolean readonly; /** @@ -138,34 +138,29 @@ public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag /** * Set the value of the '{@code disabled}' attribute. - * May be a runtime expression. */ - public void setDisabled(String disabled) { + public void setDisabled(boolean disabled) { this.disabled = disabled; } /** * Get the value of the '{@code disabled}' attribute. */ - protected String getDisabled() { + protected boolean isDisabled() { return this.disabled; } /** * Sets the value of the '{@code readonly}' attribute. - * May be a runtime expression. - * @see #isReadonly() */ - public void setReadonly(String readonly) { + public void setReadonly(boolean readonly) { this.readonly = readonly; } /** * Gets the value of the '{@code readonly}' attribute. - * May be a runtime expression. - * @see #isReadonly() */ - protected String getReadonly() { + protected boolean isReadonly() { return this.readonly; } @@ -189,21 +184,4 @@ public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag } } - /** - * Is the current HTML tag disabled? - */ - protected boolean isDisabled() throws JspException { - return evaluateBoolean(DISABLED_ATTRIBUTE, getDisabled()); - } - - /** - * Is the current HTML tag readonly? - *

Note: some {@link AbstractHtmlInputElementTag} subclasses (such a those - * for checkboxes and radiobuttons) may contain readonly attributes, but are - * not affected by them since their values don't change (only their status does.) - */ - protected boolean isReadonly() throws JspException { - return evaluateBoolean(READONLY_ATTRIBUTE, getReadonly()); - } - } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java index d3468aed0b5..efe6f5a04dd 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -35,20 +35,15 @@ public class ButtonTag extends AbstractHtmlElementTag { */ public static final String DISABLED_ATTRIBUTE = "disabled"; + private TagWriter tagWriter; private String name; private String value; - private String disabled; + private boolean disabled; - /** - * Set the value of the '{@code name}' attribute. - */ - public String getName() { - return name; - } /** * Get the value of the '{@code name}' attribute. @@ -58,10 +53,10 @@ public class ButtonTag extends AbstractHtmlElementTag { } /** - * Get the value of the '{@code value}' attribute. + * Set the value of the '{@code name}' attribute. */ - public String getValue() { - return this.value; + public String getName() { + return name; } /** @@ -72,20 +67,27 @@ public class ButtonTag extends AbstractHtmlElementTag { } /** - * Get the value of the '{@code disabled}' attribute. + * Get the value of the '{@code value}' attribute. */ - public String getDisabled() { - return this.disabled; + public String getValue() { + return this.value; } /** * Set the value of the '{@code disabled}' attribute. - * May be a runtime expression. */ - public void setDisabled(String disabled) { + public void setDisabled(boolean disabled) { this.disabled = disabled; } + /** + * Get the value of the '{@code disabled}' attribute. + */ + public boolean isDisabled() { + return this.disabled; + } + + @Override protected int writeTagContent(TagWriter tagWriter) throws JspException { tagWriter.startTag("button"); @@ -100,13 +102,6 @@ public class ButtonTag extends AbstractHtmlElementTag { return EVAL_BODY_INCLUDE; } - /** - * Is the current HTML tag disabled? - */ - protected boolean isDisabled() throws JspException { - return evaluateBoolean(DISABLED_ATTRIBUTE, getDisabled()); - } - /** * Writes the '{@code value}' attribute to the supplied {@link TagWriter}. * Subclasses may choose to override this implementation to control exactly @@ -119,7 +114,6 @@ public class ButtonTag extends AbstractHtmlElementTag { /** * Return the default value. - * * @return The default value if none supplied. */ protected String getDefaultValue() { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/HiddenInputTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/HiddenInputTag.java index 7a6de1dd26b..278d9a76b6d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/HiddenInputTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/HiddenInputTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -40,23 +40,25 @@ public class HiddenInputTag extends AbstractHtmlElementTag { */ public static final String DISABLED_ATTRIBUTE = "disabled"; - private String disabled; + private boolean disabled; - /** - * Get the value of the '{@code disabled}' attribute. - */ - public String getDisabled() { - return this.disabled; - } /** * Set the value of the '{@code disabled}' attribute. * May be a runtime expression. */ - public void setDisabled(String disabled) { + public void setDisabled(boolean disabled) { this.disabled = disabled; } + /** + * Get the value of the '{@code disabled}' attribute. + */ + public boolean isDisabled() { + return this.disabled; + } + + /** * Flags "type" as an illegal dynamic attribute. */ @@ -85,11 +87,4 @@ public class HiddenInputTag extends AbstractHtmlElementTag { return SKIP_BODY; } - /** - * Is the current HTML tag disabled? - */ - protected boolean isDisabled() throws JspException { - return evaluateBoolean(DISABLED_ATTRIBUTE, getDisabled()); - } - } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/OptionTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/OptionTag.java index 3e9ee381ce3..2e97f9e0659 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/OptionTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/OptionTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -89,12 +89,11 @@ public class OptionTag extends AbstractHtmlElementBodyTag implements BodyTag { private Object oldDisplayValue; - private String disabled; + private boolean disabled; /** * Set the 'value' attribute of the rendered HTML {@code <option>} tag. - *

May be a runtime expression. */ public void setValue(Object value) { this.value = value; @@ -109,28 +108,18 @@ public class OptionTag extends AbstractHtmlElementBodyTag implements BodyTag { /** * Set the value of the '{@code disabled}' attribute. - *

May be a runtime expression. - * @param disabled the value of the '{@code disabled}' attribute */ - public void setDisabled(String disabled) { + public void setDisabled(boolean disabled) { this.disabled = disabled; } /** * Get the value of the '{@code disabled}' attribute. */ - protected String getDisabled() { + protected boolean isDisabled() { return this.disabled; } - /** - * Is the current HTML tag disabled? - * @return {@code true} if this tag is disabled - */ - protected boolean isDisabled() throws JspException { - return evaluateBoolean(DISABLED_ATTRIBUTE, getDisabled()); - } - /** * Set the text body of the rendered HTML {@code <option>} tag. *

May be a runtime expression. diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/OptionsTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/OptionsTag.java index 0c57b8dd9be..09b7e8f0001 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/OptionsTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/OptionsTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -56,7 +56,7 @@ public class OptionsTag extends AbstractHtmlElementTag { */ private String itemLabel; - private String disabled; + private boolean disabled; /** @@ -84,7 +84,6 @@ public class OptionsTag extends AbstractHtmlElementTag { * attribute of the '{@code option}' tag. *

Required when wishing to render '{@code option}' tags from * an array or {@link java.util.Collection}. - *

May be a runtime expression. */ public void setItemValue(String itemValue) { Assert.hasText(itemValue, "'itemValue' must not be empty"); @@ -102,7 +101,6 @@ public class OptionsTag extends AbstractHtmlElementTag { /** * Set the name of the property mapped to the label (inner text) of the * '{@code option}' tag. - *

May be a runtime expression. */ public void setItemLabel(String itemLabel) { Assert.hasText(itemLabel, "'itemLabel' must not be empty"); @@ -112,7 +110,6 @@ public class OptionsTag extends AbstractHtmlElementTag { /** * Get the name of the property mapped to the label (inner text) of the * '{@code option}' tag. - *

May be a runtime expression. */ protected String getItemLabel() { return this.itemLabel; @@ -120,28 +117,18 @@ public class OptionsTag extends AbstractHtmlElementTag { /** * Set the value of the '{@code disabled}' attribute. - *

May be a runtime expression. - * @param disabled the value of the '{@code disabled}' attribute */ - public void setDisabled(String disabled) { + public void setDisabled(boolean disabled) { this.disabled = disabled; } /** * Get the value of the '{@code disabled}' attribute. */ - protected String getDisabled() { + protected boolean isDisabled() { return this.disabled; } - /** - * Is the current HTML tag disabled? - * @return {@code true} if this tag is disabled - */ - protected boolean isDisabled() throws JspException { - return evaluateBoolean("disabled", getDisabled()); - } - @Override protected int writeTagContent(TagWriter tagWriter) throws JspException { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectTag.java index e0afe0f431a..29eedb0b57e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectTag.java @@ -18,7 +18,6 @@ package org.springframework.web.servlet.tags.form; import java.util.Collection; import java.util.Map; - import javax.servlet.jsp.JspException; import org.springframework.util.ObjectUtils; @@ -153,8 +152,6 @@ public class SelectTag extends AbstractHtmlInputElementTag { /** * Set the value of the HTML '{@code size}' attribute rendered * on the final '{@code select}' element. - *

May be a runtime expression. - * @param size the desired value of the '{@code size}' attribute */ public void setSize(String size) { this.size = size; @@ -162,7 +159,6 @@ public class SelectTag extends AbstractHtmlInputElementTag { /** * Get the value of the '{@code size}' attribute. - *

May be a runtime expression. */ protected String getSize() { return this.size; @@ -171,7 +167,6 @@ public class SelectTag extends AbstractHtmlInputElementTag { /** * Set the value of the HTML '{@code multiple}' attribute rendered * on the final '{@code select}' element. - *

May be a runtime expression. */ public void setMultiple(Object multiple) { this.multiple = multiple; @@ -180,7 +175,6 @@ public class SelectTag extends AbstractHtmlInputElementTag { /** * Get the value of the HTML '{@code multiple}' attribute rendered * on the final '{@code select}' element. - *

May be a runtime expression. */ protected Object getMultiple() { return this.multiple; @@ -257,9 +251,6 @@ public class SelectTag extends AbstractHtmlInputElementTag { if (Boolean.TRUE.equals(multiple) || "multiple".equals(multiple)) { return true; } - else if (this.multiple instanceof String) { - return evaluateBoolean("multiple", (String) multiple); - } return forceMultiple(); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/AbstractTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/AbstractTagTests.java index 33ce989c947..ae1b7c081de 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/AbstractTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/AbstractTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -41,7 +41,6 @@ public abstract class AbstractTagTests extends TestCase { protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); - sc.addInitParameter("springJspExpressionSupport", "true"); SimpleWebApplicationContext wac = new SimpleWebApplicationContext(); wac.setServletContext(sc); wac.setNamespace("test"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagTests.java index 4af3a47cde6..eefeb2138b8 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/BindTagTests.java @@ -22,15 +22,14 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Set; - import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.Tag; +import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.tests.sample.beans.IndexedTestBean; import org.springframework.tests.sample.beans.NestedTestBean; import org.springframework.tests.sample.beans.TestBean; -import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.validation.BindException; import org.springframework.validation.BindingResult; import org.springframework.validation.DataBinder; @@ -228,7 +227,7 @@ public class BindTagTests extends AbstractTagTests { BindTag tag = new BindTag(); tag.setPageContext(pc); tag.setPath("tb.name"); - tag.setHtmlEscape("true"); + tag.setHtmlEscape(true); assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE); BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE); assertTrue("Has status variable", status != null); @@ -298,7 +297,7 @@ public class BindTagTests extends AbstractTagTests { BindTag tag = new BindTag(); tag.setPageContext(pc); tag.setPath("tb.name"); - tag.setHtmlEscape("true"); + tag.setHtmlEscape(true); assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE); BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE); assertTrue("Has status variable", status != null); @@ -354,7 +353,7 @@ public class BindTagTests extends AbstractTagTests { BindTag tag = new BindTag(); tag.setPageContext(pc); tag.setPath("tb.name"); - tag.setHtmlEscape("true"); + tag.setHtmlEscape(true); assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE); BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE); assertTrue("Has status variable", status != null); @@ -412,8 +411,7 @@ public class BindTagTests extends AbstractTagTests { pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors); BindTag tag = new BindTag(); tag.setPageContext(pc); - pc.setAttribute("myattr", "tb.spouse.name"); - tag.setPath("${myattr}"); + tag.setPath("tb.spouse.name"); assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE); BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE); assertTrue("Has status variable", status != null); @@ -536,7 +534,7 @@ public class BindTagTests extends AbstractTagTests { BindTag tag = new BindTag(); tag.setPageContext(pc); tag.setPath("tb.doctor"); - tag.setHtmlEscape("true"); + tag.setHtmlEscape(true); TestBean tb = new TestBean("somebody", 99); NestedTestBean ntb = new NestedTestBean("juergen&eva"); tb.setDoctor(ntb); @@ -553,7 +551,7 @@ public class BindTagTests extends AbstractTagTests { BindTag tag = new BindTag(); tag.setPageContext(pc); tag.setPath("tb.someSet"); - tag.setHtmlEscape("true"); + tag.setHtmlEscape(true); pc.getRequest().setAttribute("tb", new TestBean("juergen&eva", 99)); tag.doStartTag(); BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE); @@ -578,7 +576,7 @@ public class BindTagTests extends AbstractTagTests { BindTag tag = new BindTag(); tag.setPageContext(pc); tag.setPath("tb.name"); - tag.setHtmlEscape("true"); + tag.setHtmlEscape(true); pc.getRequest().setAttribute("tb", new TestBean("juergen&eva", 99)); tag.doStartTag(); BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE); @@ -799,9 +797,8 @@ public class BindTagTests extends AbstractTagTests { // transform stuff TransformTag transform = new TransformTag(); transform.setPageContext(pc); - pc.setAttribute("date", tb.getDate()); transform.setParent(bind); - transform.setValue("${date}"); + transform.setValue(tb.getDate()); transform.setVar("theDate"); transform.doStartTag(); @@ -816,14 +813,13 @@ public class BindTagTests extends AbstractTagTests { transform = new TransformTag(); transform.setPageContext(pc); - pc.setAttribute("string", "name"); - transform.setValue("${string}"); + transform.setValue("name"); transform.setParent(bind); transform.setVar("theString"); transform.doStartTag(); assertNotNull(pc.getAttribute("theString")); - assertEquals(pc.getAttribute("theString"), "name"); + assertEquals("name", pc.getAttribute("theString")); } public void testTransformTagWithHtmlEscape() throws JspException { @@ -844,15 +840,14 @@ public class BindTagTests extends AbstractTagTests { TransformTag transform = new TransformTag(); transform.setPageContext(pc); - pc.setAttribute("string", "na floats = new ArrayList(); + floats.add(new Float("12.30")); + floats.add(new Float("12.31")); + floats.add(new Float("12.32")); + floats.add(new Float("12.33")); + floats.add(new Float("12.34")); + floats.add(new Float("12.35")); + + this.tag.setItems(floats); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); @@ -184,11 +193,10 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests { } public void testWithItemsNullReference() throws Exception { - getPageContext().getRequest().removeAttribute("countries"); getPageContext().setAttribute( SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false)); - this.tag.setItems("${countries}"); + this.tag.setItems(Collections.emptyList()); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); int result = this.tag.doStartTag(); @@ -287,7 +295,6 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests { bean.setCountry("UK"); bean.setMyFloat(new Float("12.34")); request.setAttribute(COMMAND_NAME, bean); - request.setAttribute("countries", Country.getCountries()); List floats = new ArrayList(); floats.add(new Float("12.30")); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/RadioButtonsTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/RadioButtonsTagTests.java index 702e790c9a3..738d5cddf9b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/RadioButtonsTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/RadioButtonsTagTests.java @@ -524,7 +524,7 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests { public void testHiddenElementOmittedOnDisabled() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"foo", "bar", "baz"}); - this.tag.setDisabled("true"); + this.tag.setDisabled(true); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/SelectTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/SelectTagTests.java index 8dfc3e3e0cf..65cefe564fb 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/SelectTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/SelectTagTests.java @@ -38,11 +38,11 @@ import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; -import org.springframework.tests.sample.beans.TestBean; import org.springframework.beans.propertyeditors.CustomCollectionEditor; import org.springframework.format.Formatter; import org.springframework.format.support.FormattingConversionService; import org.springframework.mock.web.test.MockHttpServletRequest; +import org.springframework.tests.sample.beans.TestBean; import org.springframework.validation.BeanPropertyBindingResult; import org.springframework.validation.BindingResult; import org.springframework.web.servlet.support.BindStatus; @@ -129,7 +129,7 @@ public class SelectTagTests extends AbstractFormTagTests { public void testWithResolvedList() throws Exception { this.tag.setPath("country"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); assertList(true); } @@ -151,7 +151,7 @@ public class SelectTagTests extends AbstractFormTagTests { public void testWithListAndNoLabel() throws Exception { this.tag.setPath("country"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); @@ -174,7 +174,7 @@ public class SelectTagTests extends AbstractFormTagTests { public void testWithListAndTransformTagAndEditor() throws Exception { this.tag.setPath("realCountry"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), "testBean"); bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() { @Override @@ -202,7 +202,7 @@ public class SelectTagTests extends AbstractFormTagTests { public void testWithListAndEditor() throws Exception { this.tag.setPath("realCountry"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), "testBean"); @@ -226,7 +226,7 @@ public class SelectTagTests extends AbstractFormTagTests { public void testNestedPathWithListAndEditorAndNullValue() throws Exception { this.tag.setPath("bean.realCountry"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); this.tag.setMultiple("false"); @@ -264,7 +264,7 @@ public class SelectTagTests extends AbstractFormTagTests { public void testNestedPathWithListAndEditor() throws Exception { this.tag.setPath("bean.realCountry"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); TestBeanWrapper testBean = new TestBeanWrapper(); @@ -290,7 +290,7 @@ public class SelectTagTests extends AbstractFormTagTests { public void testWithListAndEditorAndNullValue() throws Exception { this.tag.setPath("realCountry"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); TestBeanWithRealCountry testBean = (TestBeanWithRealCountry) getTestBean(); @@ -321,14 +321,14 @@ public class SelectTagTests extends AbstractFormTagTests { public void testWithMap() throws Exception { this.tag.setPath("sex"); - this.tag.setItems("${sexes}"); + this.tag.setItems(getSexes()); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); } public void testWithInvalidList() throws Exception { this.tag.setPath("country"); - this.tag.setItems("${other}"); + this.tag.setItems(new TestBean()); this.tag.setItemValue("isoCode"); try { this.tag.doStartTag(); @@ -367,7 +367,7 @@ public class SelectTagTests extends AbstractFormTagTests { public void testWithResolvedStringArray() throws Exception { this.tag.setPath("name"); - this.tag.setItems("${names}"); + this.tag.setItems(getNames()); assertStringArray(); } @@ -447,7 +447,7 @@ public class SelectTagTests extends AbstractFormTagTests { this.bean.setSomeList(list); this.tag.setPath("someList"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); @@ -495,7 +495,7 @@ public class SelectTagTests extends AbstractFormTagTests { exposeBindingResult(errors); this.tag.setPath("realCountry"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); @@ -542,7 +542,7 @@ public class SelectTagTests extends AbstractFormTagTests { exposeBindingResult(errors); this.tag.setPath("someList"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); @@ -587,7 +587,7 @@ public class SelectTagTests extends AbstractFormTagTests { exposeBindingResult(errors); this.tag.setPath("someList"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); @@ -621,7 +621,7 @@ public class SelectTagTests extends AbstractFormTagTests { this.bean.setSomeMap(someMap); this.tag.setPath("someMap"); - this.tag.setItems("${sexes}"); + this.tag.setItems(getSexes()); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); @@ -681,7 +681,7 @@ public class SelectTagTests extends AbstractFormTagTests { this.bean.setSomeMap(someMap); this.tag.setPath("someMap"); // see: TestBean - this.tag.setItems("${countryToLocaleMap}"); // see: extendRequest() + this.tag.setItems(getCountryToLocaleMap()); this.tag.setItemValue("isoCode"); // Map key: Country this.tag.setItemLabel("displayLanguage"); // Map value: Locale @@ -742,7 +742,7 @@ public class SelectTagTests extends AbstractFormTagTests { this.bean.setSomeList(new ArrayList()); this.tag.setPath("someList"); - this.tag.setItems("${countries}"); + this.tag.setItems(Country.getCountries()); this.tag.setItemValue("isoCode"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); @@ -807,22 +807,12 @@ public class SelectTagTests extends AbstractFormTagTests { } private Map getSexes() { - Map sexes = new HashMap(); + Map sexes = new HashMap(); sexes.put("F", "Female"); sexes.put("M", "Male"); return sexes; } - @Override - protected void extendRequest(MockHttpServletRequest request) { - super.extendRequest(request); - request.setAttribute("countries", Country.getCountries()); - request.setAttribute("countryToLocaleMap", getCountryToLocaleMap()); - request.setAttribute("sexes", getSexes()); - request.setAttribute("other", new TestBean()); - request.setAttribute("names", getNames()); - } - private void assertList(boolean selected) throws JspException, DocumentException { this.tag.setItemValue("isoCode"); this.tag.setItemLabel("name"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/TextareaTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/TextareaTagTests.java index bfa9bd8dbe1..d624a222857 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/TextareaTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/TextareaTagTests.java @@ -47,7 +47,7 @@ public class TextareaTagTests extends AbstractFormTagTests { public void testSimpleBind() throws Exception { this.tag.setPath("name"); - this.tag.setReadonly("true"); + this.tag.setReadonly(true); assertEquals(Tag.SKIP_BODY, this.tag.doStartTag()); String output = getOutput(); @@ -61,7 +61,7 @@ public class TextareaTagTests extends AbstractFormTagTests { String dynamicAttribute2 = "attr2"; this.tag.setPath("name"); - this.tag.setReadonly("true"); + this.tag.setReadonly(true); this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1); this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);