diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ParamTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ParamTag.java index a0b62747ea..29b1f5084c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ParamTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ParamTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import javax.servlet.jsp.tagext.BodyTagSupport; *

This tag must be nested under a param aware tag. * * @author Scott Andrews + * @author Nicholas Williams * @since 3.0 * @see Param * @see UrlTag @@ -37,16 +38,16 @@ public class ParamTag extends BodyTagSupport { private String value; - private Param param; + private boolean valueSet; // tag lifecycle @Override public int doEndTag() throws JspException { - param = new Param(); - param.setName(name); - if (value != null) { - param.setValue(value); + Param param = new Param(); + param.setName(this.name); + if (this.valueSet) { + param.setValue(this.value); } else if (getBodyContent() != null) { // get the value from the tag body @@ -90,6 +91,15 @@ public class ParamTag extends BodyTagSupport { */ public void setValue(String value) { this.value = value; + this.valueSet = true; + } + + @Override + public void release() { + super.release(); + this.name = null; + this.value = null; + this.valueSet = false; } } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTagTests.java index fc6321a2c4..2be185550b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/ParamTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +25,10 @@ import org.springframework.mock.web.test.MockBodyContent; import org.springframework.mock.web.test.MockHttpServletResponse; /** - * Unit tests for ParamTag + * Unit tests for {@link ParamTag} * * @author Scott Andrews + * @author Nicholas Williams */ public class ParamTagTests extends AbstractTagTests { @@ -67,7 +68,7 @@ public class ParamTagTests extends AbstractTagTests { assertEquals("value", parent.getParam().getValue()); } - public void testParamWithNullValue() throws JspException { + public void testParamWithImplicitNullValue() throws JspException { tag.setName("name"); int action = tag.doEndTag(); @@ -77,6 +78,43 @@ public class ParamTagTests extends AbstractTagTests { assertNull(parent.getParam().getValue()); } + public void testParamWithExplicitNullValue() throws JspException { + tag.setName("name"); + tag.setValue(null); + + int action = tag.doEndTag(); + + assertEquals(Tag.EVAL_PAGE, action); + assertEquals("name", parent.getParam().getName()); + assertNull(parent.getParam().getValue()); + } + + public void testParamWithValueThenReleaseThenBodyValue() throws JspException { + tag.setName("name1"); + tag.setValue("value1"); + + int action = tag.doEndTag(); + + assertEquals(Tag.EVAL_PAGE, action); + assertEquals("name1", parent.getParam().getName()); + assertEquals("value1", parent.getParam().getValue()); + + tag.release(); + + parent = new MockParamSupportTag(); + tag.setPageContext(createPageContext()); + tag.setParent(parent); + tag.setName("name2"); + tag.setBodyContent(new MockBodyContent("value2", + new MockHttpServletResponse())); + + action = tag.doEndTag(); + + assertEquals(Tag.EVAL_PAGE, action); + assertEquals("name2", parent.getParam().getName()); + assertEquals("value2", parent.getParam().getValue()); + } + public void testParamWithNoParent() { tag.setName("name"); tag.setValue("value");