avoid rendering invalid ids (SPR-6840)
This commit is contained in:
parent
e8a4ddd3e0
commit
a6af91f7b2
|
|
@ -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 '<code>name</code>' attribute
|
||||
*/
|
||||
protected String getName() throws JspException {
|
||||
return getPropertyPath();
|
||||
return StringUtils.deleteAny(getPropertyPath(), "[]");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 = "<doc>" + output + "</doc>";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue