SelectTag correctly detects multiple="true" again
Issue: SPR-11678
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -249,7 +249,8 @@ public class SelectTag extends AbstractHtmlInputElementTag {
|
||||
|
||||
private boolean isMultiple() throws JspException {
|
||||
Object multiple = getMultiple();
|
||||
if (Boolean.TRUE.equals(multiple) || "multiple".equals(multiple)) {
|
||||
if (multiple != null && (Boolean.TRUE.equals(multiple) ||
|
||||
Boolean.parseBoolean(multiple.toString()) || "multiple".equals(multiple))) {
|
||||
return true;
|
||||
}
|
||||
return forceMultiple();
|
||||
|
||||
@@ -194,8 +194,6 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
transformTag.setParent(this.tag);
|
||||
transformTag.setPageContext(getPageContext());
|
||||
transformTag.doStartTag();
|
||||
String output = getOutput();
|
||||
System.err.println(output);
|
||||
assertEquals("Austria", getPageContext().findAttribute("key"));
|
||||
}
|
||||
|
||||
@@ -255,7 +253,6 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "testBean", bindingResult);
|
||||
this.tag.doStartTag();
|
||||
String output = getOutput();
|
||||
System.err.println(output);
|
||||
assertTrue(output.startsWith("<select "));
|
||||
assertTrue(output.endsWith("</select>"));
|
||||
assertFalse(output.contains("selected=\"selected\""));
|
||||
@@ -312,7 +309,6 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
getPageContext().getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "testBean", bindingResult);
|
||||
this.tag.doStartTag();
|
||||
String output = getOutput();
|
||||
System.err.println(output);
|
||||
assertTrue(output.startsWith("<select "));
|
||||
assertTrue(output.endsWith("</select>"));
|
||||
assertFalse(output.contains("selected=\"selected\""));
|
||||
@@ -335,8 +331,8 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
}
|
||||
catch (JspException expected) {
|
||||
String message = expected.getMessage();
|
||||
assertTrue(message.indexOf("items") > -1);
|
||||
assertTrue(message.indexOf("org.springframework.tests.sample.beans.TestBean") > -1);
|
||||
assertTrue(message.contains("items"));
|
||||
assertTrue(message.contains("org.springframework.tests.sample.beans.TestBean"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -664,7 +660,6 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
* </ul>
|
||||
*/
|
||||
public void testWithMultiMapWithItemValueAndItemLabel() throws Exception {
|
||||
|
||||
// Save original default locale.
|
||||
final Locale defaultLocale = Locale.getDefault();
|
||||
// Use a locale that doesn't result in the generation of HTML entities
|
||||
@@ -686,7 +681,6 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
|
||||
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), COMMAND_NAME);
|
||||
bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
|
||||
|
||||
@Override
|
||||
public void setAsText(final String text) throws IllegalArgumentException {
|
||||
setValue(Country.getCountryWithIsoCode(text));
|
||||
@@ -737,7 +731,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
}
|
||||
}
|
||||
|
||||
public void testMultiWithEmptyCollection() throws Exception {
|
||||
public void testMultiForCollection() throws Exception {
|
||||
this.bean.setSomeList(new ArrayList());
|
||||
|
||||
this.tag.setPath("someList");
|
||||
@@ -766,6 +760,34 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
assertNotNull(inputElement);
|
||||
}
|
||||
|
||||
public void testMultiExplicit() 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);
|
||||
}
|
||||
|
||||
|
||||
private void assertStringArray() throws JspException, DocumentException {
|
||||
int result = this.tag.doStartTag();
|
||||
|
||||
Reference in New Issue
Block a user