SelectTag consistently checks specified 'multiple' attribute now, never falling back to forceMultiple in case of user-provided value
Issue: SPR-11903
This commit is contained in:
@@ -84,7 +84,7 @@ public class SelectTag extends AbstractHtmlInputElementTag {
|
|||||||
* Indicates whether or not the '{@code select}' tag allows
|
* Indicates whether or not the '{@code select}' tag allows
|
||||||
* multiple-selections.
|
* multiple-selections.
|
||||||
*/
|
*/
|
||||||
private Object multiple = Boolean.FALSE;
|
private Object multiple;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link TagWriter} instance that the output is being written.
|
* The {@link TagWriter} instance that the output is being written.
|
||||||
@@ -249,9 +249,9 @@ public class SelectTag extends AbstractHtmlInputElementTag {
|
|||||||
|
|
||||||
private boolean isMultiple() throws JspException {
|
private boolean isMultiple() throws JspException {
|
||||||
Object multiple = getMultiple();
|
Object multiple = getMultiple();
|
||||||
if (multiple != null && (Boolean.TRUE.equals(multiple) ||
|
if (multiple != null) {
|
||||||
Boolean.parseBoolean(multiple.toString()) || "multiple".equals(multiple))) {
|
String stringValue = multiple.toString();
|
||||||
return true;
|
return ("multiple".equalsIgnoreCase(stringValue) || Boolean.parseBoolean(stringValue));
|
||||||
}
|
}
|
||||||
return forceMultiple();
|
return forceMultiple();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
|||||||
assertTrue(output.startsWith("<select "));
|
assertTrue(output.startsWith("<select "));
|
||||||
assertTrue(output.endsWith("</select>"));
|
assertTrue(output.endsWith("</select>"));
|
||||||
assertFalse(output.contains("selected=\"selected\""));
|
assertFalse(output.contains("selected=\"selected\""));
|
||||||
|
assertFalse(output.contains("multiple=\"multiple\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNestedPathWithListAndEditor() throws Exception {
|
public void testNestedPathWithListAndEditor() throws Exception {
|
||||||
@@ -731,7 +732,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultiForCollection() throws Exception {
|
public void testMultipleForCollection() throws Exception {
|
||||||
this.bean.setSomeList(new ArrayList());
|
this.bean.setSomeList(new ArrayList());
|
||||||
|
|
||||||
this.tag.setPath("someList");
|
this.tag.setPath("someList");
|
||||||
@@ -760,7 +761,35 @@ public class SelectTagTests extends AbstractFormTagTests {
|
|||||||
assertNotNull(inputElement);
|
assertNotNull(inputElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultiExplicit() throws Exception {
|
public void testMultipleWithStringValue() throws Exception {
|
||||||
|
this.tag.setPath("name");
|
||||||
|
this.tag.setItems(Country.getCountries());
|
||||||
|
this.tag.setItemValue("isoCode");
|
||||||
|
this.tag.setMultiple("multiple");
|
||||||
|
int result = this.tag.doStartTag();
|
||||||
|
assertEquals(Tag.SKIP_BODY, result);
|
||||||
|
|
||||||
|
String output = getOutput();
|
||||||
|
output = "<doc>" + output + "</doc>";
|
||||||
|
|
||||||
|
SAXReader reader = new SAXReader();
|
||||||
|
Document document = reader.read(new StringReader(output));
|
||||||
|
Element rootElement = document.getRootElement();
|
||||||
|
assertEquals(2, rootElement.elements().size());
|
||||||
|
|
||||||
|
Element selectElement = rootElement.element("select");
|
||||||
|
assertEquals("select", selectElement.getName());
|
||||||
|
assertEquals("name", selectElement.attribute("name").getValue());
|
||||||
|
assertEquals("multiple", selectElement.attribute("multiple").getValue());
|
||||||
|
|
||||||
|
List children = selectElement.elements();
|
||||||
|
assertEquals("Incorrect number of children", 4, children.size());
|
||||||
|
|
||||||
|
Element inputElement = rootElement.element("input");
|
||||||
|
assertNotNull(inputElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMultipleExplicitlyTrue() throws Exception {
|
||||||
this.tag.setPath("name");
|
this.tag.setPath("name");
|
||||||
this.tag.setItems(Country.getCountries());
|
this.tag.setItems(Country.getCountries());
|
||||||
this.tag.setItemValue("isoCode");
|
this.tag.setItemValue("isoCode");
|
||||||
@@ -788,6 +817,84 @@ public class SelectTagTests extends AbstractFormTagTests {
|
|||||||
assertNotNull(inputElement);
|
assertNotNull(inputElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testMultipleExplicitlyFalse() throws Exception {
|
||||||
|
this.tag.setPath("name");
|
||||||
|
this.tag.setItems(Country.getCountries());
|
||||||
|
this.tag.setItemValue("isoCode");
|
||||||
|
this.tag.setMultiple("false");
|
||||||
|
int result = this.tag.doStartTag();
|
||||||
|
assertEquals(Tag.SKIP_BODY, result);
|
||||||
|
|
||||||
|
String output = getOutput();
|
||||||
|
output = "<doc>" + output + "</doc>";
|
||||||
|
|
||||||
|
SAXReader reader = new SAXReader();
|
||||||
|
Document document = reader.read(new StringReader(output));
|
||||||
|
Element rootElement = document.getRootElement();
|
||||||
|
assertEquals(1, rootElement.elements().size());
|
||||||
|
|
||||||
|
Element selectElement = rootElement.element("select");
|
||||||
|
assertEquals("select", selectElement.getName());
|
||||||
|
assertEquals("name", selectElement.attribute("name").getValue());
|
||||||
|
assertNull(selectElement.attribute("multiple"));
|
||||||
|
|
||||||
|
List children = selectElement.elements();
|
||||||
|
assertEquals("Incorrect number of children", 4, children.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMultipleWithBooleanTrue() throws Exception {
|
||||||
|
this.tag.setPath("name");
|
||||||
|
this.tag.setItems(Country.getCountries());
|
||||||
|
this.tag.setItemValue("isoCode");
|
||||||
|
this.tag.setMultiple(true);
|
||||||
|
int result = this.tag.doStartTag();
|
||||||
|
assertEquals(Tag.SKIP_BODY, result);
|
||||||
|
|
||||||
|
String output = getOutput();
|
||||||
|
output = "<doc>" + output + "</doc>";
|
||||||
|
|
||||||
|
SAXReader reader = new SAXReader();
|
||||||
|
Document document = reader.read(new StringReader(output));
|
||||||
|
Element rootElement = document.getRootElement();
|
||||||
|
assertEquals(2, rootElement.elements().size());
|
||||||
|
|
||||||
|
Element selectElement = rootElement.element("select");
|
||||||
|
assertEquals("select", selectElement.getName());
|
||||||
|
assertEquals("name", selectElement.attribute("name").getValue());
|
||||||
|
assertEquals("multiple", selectElement.attribute("multiple").getValue());
|
||||||
|
|
||||||
|
List children = selectElement.elements();
|
||||||
|
assertEquals("Incorrect number of children", 4, children.size());
|
||||||
|
|
||||||
|
Element inputElement = rootElement.element("input");
|
||||||
|
assertNotNull(inputElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMultipleWithBooleanFalse() throws Exception {
|
||||||
|
this.tag.setPath("name");
|
||||||
|
this.tag.setItems(Country.getCountries());
|
||||||
|
this.tag.setItemValue("isoCode");
|
||||||
|
this.tag.setMultiple(false);
|
||||||
|
int result = this.tag.doStartTag();
|
||||||
|
assertEquals(Tag.SKIP_BODY, result);
|
||||||
|
|
||||||
|
String output = getOutput();
|
||||||
|
output = "<doc>" + output + "</doc>";
|
||||||
|
|
||||||
|
SAXReader reader = new SAXReader();
|
||||||
|
Document document = reader.read(new StringReader(output));
|
||||||
|
Element rootElement = document.getRootElement();
|
||||||
|
assertEquals(1, rootElement.elements().size());
|
||||||
|
|
||||||
|
Element selectElement = rootElement.element("select");
|
||||||
|
assertEquals("select", selectElement.getName());
|
||||||
|
assertEquals("name", selectElement.attribute("name").getValue());
|
||||||
|
assertNull(selectElement.attribute("multiple"));
|
||||||
|
|
||||||
|
List children = selectElement.elements();
|
||||||
|
assertEquals("Incorrect number of children", 4, children.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void assertStringArray() throws JspException, DocumentException {
|
private void assertStringArray() throws JspException, DocumentException {
|
||||||
int result = this.tag.doStartTag();
|
int result = this.tag.doStartTag();
|
||||||
|
|||||||
Reference in New Issue
Block a user