mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-1747 / WW-1711:
Working with real types rather than String representations as long as possible should fix both issues with select tag. Additional test added and verified. git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@509780 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
<option value="${itemKey?html}"<#rt/>
|
||||
<#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}</option><#lt/>
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<tr>
|
||||
<td class="tdLabel"><label for="collection" class="label">mylabel:</label></td>
|
||||
<td><select name="collection" id="collection" multiple="multiple" onmousedown="alert('onmousedown');" onmouseup="alert('onmouseup');" onmouseover="alert('onmouseover');" onmousemove="alert('onmousemove');" onmouseout="alert('onmouseout');">
|
||||
<option value="1" selected="selected">foo</option>
|
||||
<option value="2">bar</option>
|
||||
<option value="3" selected="selected">foobar</option>
|
||||
</select></td>
|
||||
</tr>
|
||||
Reference in New Issue
Block a user