提交 20fb4187 编写于 作者: J Juergen Hoeller

Removed Spring’s own JSP expression support (in favor of JSP 2.0+)

上级 f19f55a5
/*
* 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}.
*
* <p>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.
*
* <p><b>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.</b>
*
* @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.
* <p>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.
* <p>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);
}
}
/*
* 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);
}
}
}
/*
* 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;
......
/*
* 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);
......
/*
* 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;
}
......
/*
* 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;
}
......
/*
* 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;
}
......
/*
* 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;
}
/**
......
/*
* 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.
* <p>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[]) {
......
......@@ -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;
/**
* <p>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;
......
/*
* 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).
*
* <p>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 {
* <p>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).
* <p>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 {
......
/*
* 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) {
......
/*
* 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.
* <p>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;
}
/**
......
/*
* 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?
* <p>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());
}
}
/*
* 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() {
......
/*
* 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());
}
}
/*
* 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 &lt;option&gt;} tag.
* <p>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.
* <p>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 &lt;option&gt;} tag.
* <p>May be a runtime expression.
......
/*
* 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.
* <p>Required when wishing to render '{@code option}' tags from
* an array or {@link java.util.Collection}.
* <p>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.
* <p>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.
* <p>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.
* <p>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 {
......
......@@ -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.
* <p>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.
* <p>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.
* <p>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.
* <p>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();
}
......
/*
* 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");
......
......@@ -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<me");
transform.setValue("${string}");
transform.setValue("na<me");
transform.setParent(bind);
transform.setVar("theString");
transform.setHtmlEscape("true");
transform.setHtmlEscape(true);
transform.doStartTag();
assertNotNull(pc.getAttribute("theString"));
assertEquals(pc.getAttribute("theString"), "na&lt;me");
assertEquals("na&lt;me", pc.getAttribute("theString"));
}
public void testTransformTagOutsideBindTag() throws JspException {
......@@ -913,7 +908,7 @@ public class BindTagTests extends AbstractTagTests {
TransformTag transform = new TransformTag();
transform.setPageContext(pc);
transform.setValue("${string2}");
transform.setValue(null);
transform.setParent(bind);
transform.setVar("theString2");
transform.doStartTag();
......@@ -940,9 +935,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.setScope("page");
transform.doStartTag();
......@@ -950,7 +944,7 @@ public class BindTagTests extends AbstractTagTests {
transform.release();
assertNotNull(pc.getAttribute("theDate"));
assertEquals(pc.getAttribute("theDate"), df.format(tb.getDate()));
assertEquals(df.format(tb.getDate()), pc.getAttribute("theDate"));
// try another time, this time using Strings
bind = new BindTag();
......@@ -960,18 +954,16 @@ public class BindTagTests extends AbstractTagTests {
transform = new TransformTag();
transform.setPageContext(pc);
pc.setAttribute("string", "name");
pc.setAttribute("scopy", "page");
transform.setValue("${string}");
transform.setValue("name");
transform.setParent(bind);
transform.setVar("theString");
transform.setScope("${scopy}");
transform.setScope("page");
transform.doStartTag();
transform.release();
assertNotNull(pc.getAttribute("theString"));
assertEquals(pc.getAttribute("theString"), "name");
assertEquals("name", pc.getAttribute("theString"));
}
/**
......
/*
* 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.
......@@ -80,7 +80,7 @@ public class EvalTagTests extends AbstractTagTests {
public void testPrintHtmlEscapedAttributeResult() throws Exception {
tag.setExpression("bean.html()");
tag.setHtmlEscape("true");
tag.setHtmlEscape(true);
int action = tag.doStartTag();
assertEquals(Tag.EVAL_BODY_INCLUDE, action);
action = tag.doEndTag();
......@@ -90,7 +90,7 @@ public class EvalTagTests extends AbstractTagTests {
public void testPrintJavaScriptEscapedAttributeResult() throws Exception {
tag.setExpression("bean.js()");
tag.setJavaScriptEscape("true");
tag.setJavaScriptEscape(true);
int action = tag.doStartTag();
assertEquals(Tag.EVAL_BODY_INCLUDE, action);
action = tag.doEndTag();
......
/*
* 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.
......@@ -47,29 +47,29 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
assertTrue("Correct default", !tag.getRequestContext().isDefaultHtmlEscape());
assertTrue("Correctly applied", !testTag.isHtmlEscape());
tag.setDefaultHtmlEscape("true");
tag.setDefaultHtmlEscape(true);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
assertTrue("Correctly applied", testTag.isHtmlEscape());
tag.setDefaultHtmlEscape("false");
tag.setDefaultHtmlEscape(false);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
assertTrue("Correctly applied", !testTag.isHtmlEscape());
tag.setDefaultHtmlEscape("true");
tag.setDefaultHtmlEscape(true);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
testTag.setHtmlEscape("true");
testTag.setHtmlEscape(true);
assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
assertTrue("Correctly applied", testTag.isHtmlEscape());
testTag.setHtmlEscape("false");
testTag.setHtmlEscape(false);
assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
assertTrue("Correctly applied", !testTag.isHtmlEscape());
tag.setDefaultHtmlEscape("false");
tag.setDefaultHtmlEscape(false);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
testTag.setHtmlEscape("true");
testTag.setHtmlEscape(true);
assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
assertTrue("Correctly applied", testTag.isHtmlEscape());
testTag.setHtmlEscape("false");
testTag.setHtmlEscape(false);
assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
assertTrue("Correctly applied", !testTag.isHtmlEscape());
}
......@@ -79,15 +79,15 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
MockServletContext sc = (MockServletContext) pc.getServletContext();
sc.addInitParameter(WebUtils.HTML_ESCAPE_CONTEXT_PARAM, "true");
HtmlEscapeTag tag = new HtmlEscapeTag();
tag.setDefaultHtmlEscape("false");
tag.setDefaultHtmlEscape(false);
tag.setPageContext(pc);
tag.doStartTag();
assertTrue("Correct default", !tag.getRequestContext().isDefaultHtmlEscape());
tag.setDefaultHtmlEscape("true");
tag.setDefaultHtmlEscape(true);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
tag.setDefaultHtmlEscape("false");
tag.setDefaultHtmlEscape(false);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
}
......@@ -101,10 +101,10 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
sc.addInitParameter(WebUtils.HTML_ESCAPE_CONTEXT_PARAM, "false");
assertTrue("Correct default", !tag.getRequestContext().isDefaultHtmlEscape());
tag.setDefaultHtmlEscape("true");
tag.setDefaultHtmlEscape(true);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertTrue("Correctly enabled", tag.getRequestContext().isDefaultHtmlEscape());
tag.setDefaultHtmlEscape("false");
tag.setDefaultHtmlEscape(false);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertTrue("Correctly disabled", !tag.getRequestContext().isDefaultHtmlEscape());
}
......@@ -144,7 +144,7 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
}
};
tag.setPageContext(pc);
tag.setHtmlEscape("true");
tag.setHtmlEscape(true);
assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
assertEquals("test &amp; text", result.toString());
......@@ -165,7 +165,7 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
}
};
tag.setPageContext(pc);
tag.setJavaScriptEscape("true");
tag.setJavaScriptEscape(true);
assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
assertEquals("Correct content", "\\' test & text \\\\", result.toString());
......@@ -186,8 +186,8 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
}
};
tag.setPageContext(pc);
tag.setHtmlEscape("true");
tag.setJavaScriptEscape("true");
tag.setHtmlEscape(true);
tag.setJavaScriptEscape(true);
assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag());
assertEquals(Tag.SKIP_BODY, tag.doAfterBody());
assertEquals("Correct content", "&#39; test &amp; text \\\\", result.toString());
......
/*
* 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.
......@@ -39,7 +39,7 @@ import org.springframework.web.servlet.support.RequestContextUtils;
public class MessageTagTests extends AbstractTagTests {
@SuppressWarnings("serial")
public void testMessageTagWithMessageSourceResolvable1() throws JspException {
public void testMessageTagWithMessageSourceResolvable() throws JspException {
PageContext pc = createPageContext();
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
......@@ -55,24 +55,7 @@ public class MessageTagTests extends AbstractTagTests {
}
@SuppressWarnings("serial")
public void testMessageTagWithMessageSourceResolvable2() throws JspException {
PageContext pc = createPageContext();
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
pc.setAttribute("myattr", new DefaultMessageSourceResolvable("test"));
tag.setMessage("${myattr}");
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "test message", message.toString());
}
@SuppressWarnings("serial")
public void testMessageTagWithCode1() throws JspException {
public void testMessageTagWithCode() throws JspException {
PageContext pc = createPageContext();
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
......@@ -87,26 +70,6 @@ public class MessageTagTests extends AbstractTagTests {
assertEquals("Correct message", "test message", message.toString());
}
@SuppressWarnings("serial")
public void testMessageTagWithCode2() throws JspException {
PageContext pc = createPageContext();
MockHttpServletRequest request = (MockHttpServletRequest) pc.getRequest();
request.addPreferredLocale(Locale.CANADA);
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
pc.setAttribute("myattr", "test");
tag.setCode("${myattr}");
tag.setHtmlEscape("true");
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "Canadian &amp; test message", message.toString());
}
@SuppressWarnings("serial")
public void testMessageTagWithNullCode() throws JspException {
PageContext pc = createPageContext();
......@@ -210,81 +173,7 @@ public class MessageTagTests extends AbstractTagTests {
}
@SuppressWarnings("serial")
public void testMessageTagWithCodeAndExpressionArgument() throws JspException {
PageContext pc = createPageContext();
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
tag.setCode("testArgs");
tag.setArguments("${arg1}");
pc.setAttribute("arg1", "my,value");
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "test my,value message {1}", message.toString());
}
@SuppressWarnings("serial")
public void testMessageTagWithCodeAndExpressionArguments() throws JspException {
PageContext pc = createPageContext();
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
tag.setCode("testArgs");
tag.setArguments("${arg1},${arg2}");
pc.setAttribute("arg1", "my,value");
pc.setAttribute("arg2", new Integer(5));
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "test my,value message 5", message.toString());
}
@SuppressWarnings("serial")
public void testMessageTagWithCodeAndExpressionArgumentArray() throws JspException {
PageContext pc = createPageContext();
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
tag.setCode("testArgs");
tag.setArguments("${argArray}");
pc.setAttribute("argArray", new Object[] {"my,value", new Integer(5)});
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "test my,value message 5", message.toString());
}
@SuppressWarnings("serial")
public void testMessageTagWithCodeAndExpressionArgumentFormat() throws JspException {
PageContext pc = createPageContext();
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
tag.setCode("testArgsFormat");
tag.setArguments("${arg1},${arg2}");
pc.setAttribute("arg1", "my,value");
pc.setAttribute("arg2", new Float(5.145));
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "test my,value message 5.14 X", message.toString());
}
@SuppressWarnings("serial")
public void testMessageTagWithCodeAndText1() throws JspException {
public void testMessageTagWithCodeAndText() throws JspException {
PageContext pc = createPageContext();
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
......@@ -300,24 +189,6 @@ public class MessageTagTests extends AbstractTagTests {
assertEquals("Correct message", "test message", (message.toString()));
}
@SuppressWarnings("serial")
public void testMessageTagWithCodeAndText2() throws JspException {
PageContext pc = createPageContext();
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
pc.setAttribute("myattr", "test & text");
tag.setCode("test2");
tag.setText("${myattr}");
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "test & text", message.toString());
}
@SuppressWarnings("serial")
public void testMessageTagWithText() throws JspException {
PageContext pc = createPageContext();
......@@ -330,30 +201,11 @@ public class MessageTagTests extends AbstractTagTests {
};
tag.setPageContext(pc);
tag.setText("test & text");
tag.setHtmlEscape("true");
tag.setHtmlEscape(true);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "test &amp; text", message.toString());
}
@SuppressWarnings("serial")
public void testMessageTagWithTextAndExpressionArgumentFormat() throws JspException {
PageContext pc = createPageContext();
final StringBuffer message = new StringBuffer();
MessageTag tag = new MessageTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
tag.setText("test {0} message {1,number,#.##} X");
tag.setArguments("${arg1},${arg2}");
pc.setAttribute("arg1", "my,value");
pc.setAttribute("arg2", new Float(5.145));
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "test my,value message 5.14 X", message.toString());
}
@SuppressWarnings("serial")
public void testMessageTagWithTextAndJavaScriptEscape() throws JspException {
PageContext pc = createPageContext();
......@@ -366,7 +218,7 @@ public class MessageTagTests extends AbstractTagTests {
};
tag.setPageContext(pc);
tag.setText("' test & text \\");
tag.setJavaScriptEscape("true");
tag.setJavaScriptEscape(true);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "\\' test & text \\\\", message.toString());
}
......@@ -383,8 +235,8 @@ public class MessageTagTests extends AbstractTagTests {
};
tag.setPageContext(pc);
tag.setText("' test & text \\");
tag.setHtmlEscape("true");
tag.setJavaScriptEscape("true");
tag.setHtmlEscape(true);
tag.setJavaScriptEscape(true);
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
assertEquals("Correct message", "&#39; test &amp; text \\\\", message.toString());
}
......
......@@ -34,8 +34,6 @@ import org.springframework.mock.web.test.MockPageContext;
import org.springframework.util.ReflectionUtils;
/**
* Unit tests for UrlTag
*
* @author Scott Andrews
*/
public class UrlTagTests extends AbstractTagTests {
......@@ -118,7 +116,7 @@ public class UrlTagTests extends AbstractTagTests {
public void testSetHtmlEscapeFalse() throws JspException {
tag.setValue("url/path");
tag.setVar("var");
tag.setHtmlEscape("false");
tag.setHtmlEscape(false);
tag.doStartTag();
......@@ -141,7 +139,7 @@ public class UrlTagTests extends AbstractTagTests {
public void testSetHtmlEscapeTrue() throws JspException {
tag.setValue("url/path");
tag.setVar("var");
tag.setHtmlEscape("true");
tag.setHtmlEscape(true);
tag.doStartTag();
......@@ -164,7 +162,7 @@ public class UrlTagTests extends AbstractTagTests {
public void testSetJavaScriptEscapeTrue() throws JspException {
tag.setValue("url/path");
tag.setVar("var");
tag.setJavaScriptEscape("true");
tag.setJavaScriptEscape(true);
tag.doStartTag();
......@@ -187,8 +185,8 @@ public class UrlTagTests extends AbstractTagTests {
public void testSetHtmlAndJavaScriptEscapeTrue() throws JspException {
tag.setValue("url/path");
tag.setVar("var");
tag.setHtmlEscape("true");
tag.setJavaScriptEscape("true");
tag.setHtmlEscape(true);
tag.setJavaScriptEscape(true);
tag.doStartTag();
......
......@@ -55,7 +55,7 @@ public class ButtonTagTests extends AbstractFormTagTests {
}
public void testDisabled() throws Exception {
this.tag.setDisabled("true");
this.tag.setDisabled(true);
this.tag.doStartTag();
this.tag.doEndTag();
......
......@@ -596,7 +596,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
public void testHiddenElementOmittedOnDisabled() throws Exception {
this.tag.setPath("someBoolean");
this.tag.setDisabled("true");
this.tag.setDisabled(true);
int result = this.tag.doStartTag();
assertEquals(Tag.SKIP_BODY, result);
String output = getOutput();
......
......@@ -671,7 +671,7 @@ public class CheckboxesTagTests 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();
......
......@@ -225,7 +225,7 @@ public class ErrorsTagTests extends AbstractFormTagTests {
}
public void testWithNonEscapedErrors() throws Exception {
this.tag.setHtmlEscape("false");
this.tag.setHtmlEscape(false);
// construct an errors instance of the tag
TestBean target = new TestBean();
......
......@@ -211,7 +211,7 @@ public class FormTagTests extends AbstractHtmlElementTagTests {
public void testWithNullResolvedCommand() throws Exception {
try {
tag.setCommandName("${null}");
tag.setCommandName(null);
tag.doStartTag();
fail("Must not be able to have a command name that resolves to null");
}
......
......@@ -87,7 +87,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
}
public void testDisabledTrue() throws Exception {
this.tag.setDisabled("true");
this.tag.setDisabled(true);
this.tag.doStartTag();
this.tag.doEndTag();
......@@ -102,7 +102,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
// SPR-8661
public void testDisabledFalse() throws Exception {
this.tag.setDisabled("false");
this.tag.setDisabled(false);
this.tag.doStartTag();
this.tag.doEndTag();
......
......@@ -133,7 +133,7 @@ public class InputTagTests extends AbstractFormTagTests {
String lang = "en";
String dir = "ltr";
String tabindex = "2";
String disabled = "true";
boolean disabled = true;
String onclick = "doClick()";
String ondblclick = "doDblclick()";
String onkeydown = "doKeydown()";
......@@ -151,7 +151,7 @@ public class InputTagTests extends AbstractFormTagTests {
String maxlength = "12";
String alt = "Some text";
String onselect = "doSelect()";
String readonly = "true";
boolean readonly = true;
String autocomplete = "off";
String dynamicAttribute1 = "attr1";
String dynamicAttribute2 = "attr2";
......@@ -285,7 +285,7 @@ public class InputTagTests extends AbstractFormTagTests {
public void testDisabledFalse() throws Exception {
this.tag.setPath("name");
this.tag.setDisabled("false");
this.tag.setDisabled(false);
this.tag.doStartTag();
String output = getOutput();
......@@ -314,7 +314,7 @@ public class InputTagTests extends AbstractFormTagTests {
*/
public void testReadOnlyAttributeRenderingWhenReadonlyIsTrue() throws Exception {
this.tag.setPath("name");
this.tag.setReadonly("true");
this.tag.setReadonly(true);
assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());
......@@ -327,24 +327,6 @@ public class InputTagTests extends AbstractFormTagTests {
assertValueAttribute(output, "Rob");
}
/**
* See SPR-3127 (http://opensource.atlassian.com/projects/spring/browse/SPR-3127)
*/
public void testReadOnlyAttributeRenderingWhenReadonlyIsFalse() throws Exception {
this.tag.setPath("name");
this.tag.setReadonly("nope, this is not readonly");
assertEquals(Tag.SKIP_BODY, this.tag.doStartTag());
String output = getOutput();
assertTagOpened(output);
assertTagClosed(output);
assertContainsAttribute(output, "type", getType());
assertAttributeNotPresent(output, "readonly");
assertValueAttribute(output, "Rob");
}
public void testDynamicTypeAttribute() throws JspException {
this.tag.setPath("myFloat");
this.tag.setDynamicAttribute(null, "type", "number");
......
......@@ -21,15 +21,14 @@ import java.beans.PropertyEditorSupport;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.Tag;
import org.springframework.tests.sample.beans.Colour;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.propertyeditors.StringArrayPropertyEditor;
import org.springframework.mock.web.test.MockBodyContent;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.tests.sample.beans.Colour;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.StringUtils;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.web.servlet.support.BindStatus;
......@@ -78,7 +77,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
this.tag.setValue("bar");
this.tag.setLabel("Bar");
this.tag.setDisabled("true");
this.tag.setDisabled(true);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
......@@ -297,8 +296,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
public void testWithCustomObjectSelected() throws Exception {
String selectName = "testBean.someNumber";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
this.tag.setValue("${myNumber}");
this.tag.setLabel("GBP ${myNumber}");
this.tag.setValue(new Float(12.34));
this.tag.setLabel("GBP 12.34");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
......@@ -316,8 +315,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
public void testWithCustomObjectNotSelected() throws Exception {
String selectName = "testBean.someNumber";
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
this.tag.setValue("${myOtherNumber}");
this.tag.setLabel("GBP ${myOtherNumber}");
this.tag.setValue(new Float(12.35));
this.tag.setLabel("GBP 12.35");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
result = this.tag.doEndTag();
......@@ -344,8 +343,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue("${myNumber}");
this.tag.setLabel("${myNumber}");
this.tag.setValue(new Float(12.34));
this.tag.setLabel("12.34f");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
......@@ -370,8 +369,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
};
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
this.tag.setValue("${myOtherNumber}");
this.tag.setLabel("${myOtherNumber}");
this.tag.setValue(new Float(12.35));
this.tag.setLabel("12.35f");
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
......@@ -458,9 +457,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);
RulesVariant rulesVariant = new RulesVariant("someRules", "someVariant");
getPageContext().getRequest().setAttribute("rule", rulesVariant);
this.tag.setValue("${rule}");
this.tag.setValue(rulesVariant);
int result = this.tag.doStartTag();
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
......@@ -522,8 +519,6 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
bean.setFriends(friends);
request.setAttribute("testBean", bean);
request.setAttribute("myNumber", new Float(12.34));
request.setAttribute("myOtherNumber", new Float(12.35));
}
......
......@@ -19,10 +19,10 @@ package org.springframework.web.servlet.tags.form;
import java.beans.PropertyEditor;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.Tag;
......@@ -31,9 +31,10 @@ import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockPageContext;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
......@@ -84,7 +85,7 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
getPageContext().setAttribute(
SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false));
this.tag.setItems("${countries}");
this.tag.setItems(Country.getCountries());
this.tag.setItemValue("isoCode");
this.tag.setItemLabel("name");
this.tag.setId("myOption");
......@@ -116,7 +117,7 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
getPageContext().setAttribute(
SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false));
this.tag.setItems("${countries}");
this.tag.setItems(Country.getCountries());
this.tag.setItemValue("isoCode");
this.tag.setItemLabel("name");
this.tag.setId("myOption");
......@@ -159,7 +160,15 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
getPageContext().setAttribute(
SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.myFloat", false));
this.tag.setItems("${floats}");
List<Float> floats = new ArrayList<Float>();
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"));
......
......@@ -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();
......
......@@ -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<String, String> sexes = new HashMap<String, String>();
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");
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册