mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
WW-2863 Appending the user's 'onchange' to the default.
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@768476 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -24,6 +24,7 @@ package org.apache.struts2.components;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang.xwork.StringUtils;
|
||||
import org.apache.struts2.views.annotations.StrutsTag;
|
||||
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
@@ -59,8 +60,12 @@ public class DoubleSelect extends DoubleListUIBean {
|
||||
|
||||
public void evaluateExtraParams() {
|
||||
super.evaluateExtraParams();
|
||||
|
||||
StringBuilder onchangeParam = new StringBuilder();
|
||||
onchangeParam.append(getParameters().get("id")).append("Redirect(this.options.selectedIndex)");
|
||||
if(StringUtils.isNotEmpty(this.onchange)) {
|
||||
onchangeParam.append(";").append(this.onchange);
|
||||
}
|
||||
// force the onchange parameter
|
||||
addParameter("onchange", getParameters().get("id") + "Redirect(this.options.selectedIndex)");
|
||||
addParameter("onchange", onchangeParam.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,70 @@ public class DoubleSelectTest extends AbstractUITagTest {
|
||||
|
||||
verify(SelectTag.class.getResource("DoubleSelect-1.txt"));
|
||||
}
|
||||
|
||||
public void testOnchange() throws Exception {
|
||||
TestAction testAction = (TestAction) action;
|
||||
|
||||
Region antwerp = new Region("Antwerp", "AN");
|
||||
Region gent = new Region("Gent", "GN");
|
||||
Region brugge = new Region("Brugge", "BRG");
|
||||
ArrayList belgiumRegions = new ArrayList();
|
||||
belgiumRegions.add(antwerp);
|
||||
belgiumRegions.add(gent);
|
||||
belgiumRegions.add(brugge);
|
||||
Country belgium = new Country("Belgium", "BE", belgiumRegions);
|
||||
|
||||
Region paris = new Region("Paris", "PA");
|
||||
Region bordeaux = new Region("Bordeaux", "BOR");
|
||||
ArrayList franceRegions = new ArrayList();
|
||||
franceRegions.add(paris);
|
||||
franceRegions.add(bordeaux);
|
||||
Country france = new Country("France", "FR", franceRegions);
|
||||
|
||||
Collection collection = new ArrayList(2);
|
||||
collection.add("AN");
|
||||
testAction.setCollection(collection);
|
||||
|
||||
List countries = new ArrayList();
|
||||
countries.add(belgium);
|
||||
countries.add(france);
|
||||
|
||||
testAction.setList2(countries);
|
||||
|
||||
DoubleSelectTag tag = new DoubleSelectTag();
|
||||
tag.setPageContext(pageContext);
|
||||
tag.setLabel("mylabel");
|
||||
tag.setName("foo");
|
||||
tag.setDoubleName("region");
|
||||
|
||||
tag.setList("list2");
|
||||
tag.setDoubleList("regions");
|
||||
|
||||
tag.setListKey("iso");
|
||||
tag.setDoubleListKey("key");
|
||||
tag.setListValue("name");
|
||||
tag.setDoubleListValue("name");
|
||||
|
||||
tag.setFormName("inputForm");
|
||||
|
||||
tag.setOnmousedown("window.status='onmousedown';");
|
||||
tag.setOnmousemove("window.status='onmousemove';");
|
||||
tag.setOnmouseout("window.status='onmouseout';");
|
||||
tag.setOnmouseover("window.status='onmouseover';");
|
||||
tag.setOnmouseup("window.status='onmouseup';");
|
||||
tag.setOnchange("window.status='onchange';");
|
||||
|
||||
//css style and class
|
||||
tag.setCssClass("c1");
|
||||
tag.setCssStyle("s1");
|
||||
tag.setDoubleCssClass("c2");
|
||||
tag.setDoubleCssStyle("s2");
|
||||
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
|
||||
verify(SelectTag.class.getResource("DoubleSelect-4.txt"));
|
||||
}
|
||||
|
||||
|
||||
public void testDoubleWithDefaultSelectedValues() throws Exception {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<tr>
|
||||
<td class="tdLabel"><label for="foo" class="label">mylabel:</label></td>
|
||||
<td>
|
||||
<select name="foo" id="foo" class="c1" style="s1" onmousedown="window.status='onmousedown';" onmouseup="window.status='onmouseup';" onmouseover="window.status='onmouseover';" onmousemove="window.status='onmousemove';" onmouseout="window.status='onmouseout';" onchange="fooRedirect(this.options.selectedIndex);window.status='onchange';">
|
||||
<option value="BE">Belgium</option>
|
||||
<option value="FR">France</option>
|
||||
</select>
|
||||
<br/>
|
||||
<select name="region" id="region" class="c2" style="s2">
|
||||
</select>
|
||||
<script type="text/javascript">
|
||||
var fooGroup = new Array(2 + 0);
|
||||
for (i = 0; i < (2 + 0); i++)
|
||||
fooGroup[i] = new Array();
|
||||
|
||||
fooGroup[0][0] = new Option("Antwerp", "AN");
|
||||
fooGroup[0][1] = new Option("Gent", "GN");
|
||||
fooGroup[0][2] = new Option("Brugge", "BRG");
|
||||
fooGroup[1][0] = new Option("Paris", "PA");
|
||||
fooGroup[1][1] = new Option("Bordeaux", "BOR");
|
||||
|
||||
var fooTemp = document.inputForm.region;
|
||||
fooRedirect(0);
|
||||
|
||||
function fooRedirect(x) {
|
||||
var selected = false;
|
||||
for (m = fooTemp.options.length - 1; m >= 0; m--) {
|
||||
fooTemp.options[m] = null;
|
||||
}
|
||||
|
||||
for (i = 0; i < fooGroup[x].length; i++) {
|
||||
fooTemp.options[i] = new Option(fooGroup[x][i].text, fooGroup[x][i].value);
|
||||
}
|
||||
|
||||
if ((fooTemp.options.length > 0) && (! selected)) {
|
||||
fooTemp.options[0].selected = true;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</td>
|
||||
</tr>
|
||||
Reference in New Issue
Block a user