我正在尝试根据第一个列表中选择的值执行级联下拉列表,第二个列表中的值应该更改。下面是代码
XHTML:
<td width="42.5%" style="background-color: #DDEEF5;"><h:selectOneMenu
value="#{loginBean.dropDownValue}" itemValue="#{dropDownValue}">
<f:selectItem itemValue="****select***" />
<f:selectItems value="#{loginBean.testDropDown}"/>
<f:ajax event="change" listner="#{loginBean.getTestDropDownTwo}" render="testDropDownTwo" />
</h:selectOneMenu></td>
<td width="42.5%" style="background-color: #DDEEF5;">If model
users are shared with regulators please select the names(s) of the
regulator</td>
</tr>
<tr>
<td width="15%" background="red" style="background-color: #9ABDE7;">
<b>Regulator Area*</b>
</td>
<td width="42.5%" style="background-color: #DDEEF5;"><h:selectOneMenu
value="#{loginBean.dropDownTwoValue}" id="testDropDownTwo">
<f:selectItem itemValue="****select***" />
<f:selectItems value="#{loginBean.testDropDownTwo}" />
</h:selectOneMenu></td>
Bean代码:
/ ** * LoginBean.java * * /
package com.tutorial;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
public class LoginBean
{
private String name;
private String password;
private String dropDownValue;
private String dropDownTwoValue;
List<SelectItem> testDropDown = new ArrayList<SelectItem>();
List<SelectItem> testDropDownTwo = new ArrayList<SelectItem>();
public String getDropDownValue() {
return dropDownValue;
}
public void setDropDownValue(String dropDownValue) {
this.dropDownValue = dropDownValue;
}
public String getDropDownTwoValue() {
return dropDownTwoValue;
}
public void setDropDownTwoValue(String dropDownTwoValue) {
this.dropDownTwoValue = dropDownTwoValue;
}
public List<SelectItem> getTestDropDown() {
testDropDown.add(new SelectItem("One"));
testDropDown.add(new SelectItem("Two"));
testDropDown.add(new SelectItem("Three"));
testDropDown.add(new SelectItem("Four"));
return testDropDown;
}
public List<SelectItem> getTestDropDownTwo() {
String dp = getDropDownValue();
if(dp != null) {
System.out.println("**********************getTestDropDownTwo********************************"+dp);
if(dp.equalsIgnoreCase("One")) {
testDropDownTwo.add(new SelectItem("One - One"));
testDropDownTwo.add(new SelectItem("One - Two"));
testDropDownTwo.add(new SelectItem("One - Three"));
testDropDownTwo.add(new SelectItem("One - Four"));
} else if(dp.equalsIgnoreCase("Two")) {
testDropDownTwo.add(new SelectItem("Two - One"));
testDropDownTwo.add(new SelectItem("Two - Two"));
testDropDownTwo.add(new SelectItem("Two - Three"));
testDropDownTwo.add(new SelectItem("Two - Four"));
}else if(dp.equalsIgnoreCase("Two")) {
testDropDownTwo.add(new SelectItem("Three - One"));
testDropDownTwo.add(new SelectItem("Three - Two"));
testDropDownTwo.add(new SelectItem("Three - Three"));
testDropDownTwo.add(new SelectItem("Three - Four"));
}else {
testDropDownTwo.add(new SelectItem("Four - One"));
testDropDownTwo.add(new SelectItem("Four - Two"));
testDropDownTwo.add(new SelectItem("Four - Three"));
testDropDownTwo.add(new SelectItem("Four - Four"));
}
}
return testDropDownTwo;
}
public void setTestDropDownTwo(List<SelectItem> testDropDownTwo) {
this.testDropDownTwo = testDropDownTwo;
}
public void setTestDropDown(List<SelectItem> testDropDown) {
this.testDropDown = testDropDown;
}
public String getName ()
{
return name;
}
public void setName (final String name)
{
this.name = name;
}
public String getPassword ()
{
return password;
}
public void setPassword (final String password)
{
this.password = password;
}
public String submit() {
// Do your thing here.
// ...
System.out.println("****LoginBean***submit***");
return "login";
}
}
请在这方面帮助我