diff --git a/core/src/main/java/org/apache/struts2/util/ContainUtil.java b/core/src/main/java/org/apache/struts2/util/ContainUtil.java index 214ddf974..ac61f95da 100644 --- a/core/src/main/java/org/apache/struts2/util/ContainUtil.java +++ b/core/src/main/java/org/apache/struts2/util/ContainUtil.java @@ -80,7 +80,7 @@ public class ContainUtil { return true; } } else if (obj1 instanceof Collection) { - if (((Collection) obj1).contains(obj2)) { + if (((Collection) obj1).contains(obj2) || ((Collection) obj1).contains(obj2.toString())) { //log.debug("obj1 is a collection and contains obj2"); return true; } diff --git a/core/src/main/resources/template/simple/select.ftl b/core/src/main/resources/template/simple/select.ftl index 835765293..43f684299 100644 --- a/core/src/main/resources/template/simple/select.ftl +++ b/core/src/main/resources/template/simple/select.ftl @@ -39,13 +39,13 @@ #if> <@s.iterator value="parameters.list"> <#if parameters.listKey?exists> - <#if stack.findString(parameters.listKey)?exists> - <#assign itemKey = stack.findString(parameters.listKey).toString()/> + <#if stack.findValue(parameters.listKey)?exists> + <#assign itemKey = stack.findValue(parameters.listKey)/> <#else> <#assign itemKey = ''/> #if> <#else> - <#assign itemKey = stack.findValue('top').toString()/> + <#assign itemKey = stack.findValue('top')/> #if> <#if parameters.listValue?exists> <#if stack.findString(parameters.listValue)?exists> @@ -57,7 +57,7 @@ <#assign itemValue = stack.findString('top')/> #if> - <#if tag.contains(parameters.nameValue, itemKey) == true || (parameters.nameValue?exists && parameters.nameValue?string == itemKey)> + <#if tag.contains(parameters.nameValue, itemKey) == true || (parameters.nameValue?exists && parameters.nameValue?string == itemKey?string)> selected="selected"<#rt/> #if> >${itemValue?html}<#lt/> diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java index 2ffbac16f..da30990f9 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java @@ -170,6 +170,33 @@ public class SelectTest extends AbstractUITagTest { } } + public class LongObject { + private Long id; + private String value; + + + public LongObject(Long id, String value) { + this.id = id; + this.value = value; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + public void testNullList() throws Exception { TestAction testAction = (TestAction) action; testAction.setList2(null); @@ -239,6 +266,44 @@ public class SelectTest extends AbstractUITagTest { verify(SelectTag.class.getResource("Select-2.txt")); } + /** + * WW-1747 - should be a valid test case for the described issue + * @throws Exception + */ + public void testMultipleWithLists() throws Exception { + TestAction testAction = (TestAction) action; + Collection collection = new ArrayList(2); + + collection.add(1l); + collection.add(3l); + testAction.setCollection(collection); + + List selectList = new ArrayList(); + selectList.add(new LongObject(1l, "foo")); + selectList.add(new LongObject(2l, "bar")); + selectList.add(new LongObject(3l, "foobar")); + testAction.setList2(selectList); + + SelectTag tag = new SelectTag(); + tag.setPageContext(pageContext); + tag.setLabel("mylabel"); + tag.setName("collection"); + tag.setList("list2"); + tag.setListKey("id"); + tag.setListValue("value"); + tag.setMultiple("true"); + tag.setOnmousedown("alert('onmousedown');"); + tag.setOnmousemove("alert('onmousemove');"); + tag.setOnmouseout("alert('onmouseout');"); + tag.setOnmouseover("alert('onmouseover');"); + tag.setOnmouseup("alert('onmouseup');"); + + tag.doStartTag(); + tag.doEndTag(); + + verify(SelectTag.class.getResource("Select-12.txt")); + } + public void testSimple() throws Exception { TestAction testAction = (TestAction) action; testAction.setFoo("hello"); diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Select-12.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Select-12.txt new file mode 100644 index 000000000..4e913b273 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Select-12.txt @@ -0,0 +1,8 @@ +