diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/AbstractDataBoundFormElementTag.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/AbstractDataBoundFormElementTag.java
index a539bb32b45..2807c08a9b7 100644
--- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/AbstractDataBoundFormElementTag.java
+++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/form/AbstractDataBoundFormElementTag.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * Copyright 2002-2010 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.form;
import java.beans.PropertyEditor;
-
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
@@ -145,7 +144,7 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im
* deleting invalid characters (such as "[" or "]").
*/
protected String autogenerateId() throws JspException {
- return StringUtils.deleteAny(getName(), "[]");
+ return getName();
}
/**
@@ -158,7 +157,7 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im
* @return the value for the HTML 'name' attribute
*/
protected String getName() throws JspException {
- return getPropertyPath();
+ return StringUtils.deleteAny(getPropertyPath(), "[]");
}
/**
diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/form/CheckboxTagTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/form/CheckboxTagTests.java
index 0ad6553f742..e9ab68efc50 100644
--- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/form/CheckboxTagTests.java
+++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/tags/form/CheckboxTagTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * Copyright 2002-2010 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,8 +21,9 @@ import java.io.StringReader;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.List;
-
+import java.util.Map;
import javax.servlet.jsp.tagext.Tag;
import org.dom4j.Document;
@@ -72,11 +73,34 @@ public class CheckboxTagTests extends AbstractFormTagTests {
Element checkboxElement = (Element) rootElement.elements().get(0);
assertEquals("input", checkboxElement.getName());
assertEquals("checkbox", checkboxElement.attribute("type").getValue());
+ assertEquals("someBoolean1", checkboxElement.attribute("id").getValue());
assertEquals("someBoolean", checkboxElement.attribute("name").getValue());
assertEquals("checked", checkboxElement.attribute("checked").getValue());
assertEquals("true", checkboxElement.attribute("value").getValue());
}
+ public void testWithIndexedBooleanObjectNotChecked() throws Exception {
+ this.tag.setPath("someMap[key]");
+ int result = this.tag.doStartTag();
+ assertEquals(Tag.SKIP_BODY, result);
+ String output = getOutput();
+
+ // wrap the output so it is valid XML
+ output = "" + output + "";
+
+ SAXReader reader = new SAXReader();
+ Document document = reader.read(new StringReader(output));
+ Element rootElement = document.getRootElement();
+ assertEquals("Both tag and hidden element not rendered", 2, rootElement.elements().size());
+ Element checkboxElement = (Element) rootElement.elements().get(0);
+ assertEquals("input", checkboxElement.getName());
+ assertEquals("checkbox", checkboxElement.attribute("type").getValue());
+ assertEquals("someMapkey1", checkboxElement.attribute("id").getValue());
+ assertEquals("someMapkey", checkboxElement.attribute("name").getValue());
+ assertEquals("checked", checkboxElement.attribute("checked").getValue());
+ assertEquals("true", checkboxElement.attribute("value").getValue());
+ }
+
public void testWithSingleValueBooleanObjectCheckedAndDynamicAttributes() throws Exception {
String dynamicAttribute1 = "attr1";
String dynamicAttribute2 = "attr2";
@@ -609,6 +633,13 @@ public class CheckboxTagTests extends AbstractFormTagTests {
pets.add(new Pet("Fluffy"));
pets.add(new Pet("Mufty"));
+ List someList = new ArrayList();
+ someList.add("foo");
+ someList.add("bar");
+
+ Map someMap = new LinkedHashMap();
+ someMap.put("key", Boolean.TRUE);
+
this.bean = new TestBean();
this.bean.setDate(getDate());
this.bean.setName("Rob Harrop");
@@ -618,10 +649,8 @@ public class CheckboxTagTests extends AbstractFormTagTests {
this.bean.setSomeIntegerArray(new Integer[] {new Integer(2), new Integer(1)});
this.bean.setOtherColours(colours);
this.bean.setPets(pets);
- List list = new ArrayList();
- list.add("foo");
- list.add("bar");
- this.bean.setSomeList(list);
+ this.bean.setSomeList(someList);
+ this.bean.setSomeMap(someMap);
return this.bean;
}