提交 50bd70f1 编写于 作者: N Nicholas Williams 提交者: Phillip Webb

Ensure ParamTag release resources

Update ParamTag to reset values when resources are released. This
prevents problems in containers that pool tags.

Issue: SPR-10769
上级 110db37f
/*
* 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;
* <p>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;
}
}
/*
* 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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册