我遇到了一种奇怪的行为。我的项目中有级联要求,所以我在我的个人笔记本电脑上做了一个小代码片段,但是同样的事情在我的项目中无法解释下面的场景:
Bean代码:
/**
* LoginBean.java
*/
package com.tutorial;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.model.SelectItem;
public class LoginBean
{
private String name;
private String password;
private String dropDownValue;
private String dropDownTwoValue;
Set<SelectItem> testDropDown = new HashSet<SelectItem>();
Set<SelectItem> testDropDownTwo = new HashSet<SelectItem>();
Set<SelectItem> hhs = new HashSet<SelectItem>();
public String getDropDownValue() {
System.out.println("getttttttttttttttttttt");
return dropDownValue;
}
public void setDropDownValue(String dropDownValue) {
this.dropDownValue = dropDownValue;
}
public String getDropDownTwoValue() {
return dropDownTwoValue;
}
public void setDropDownTwoValue(String dropDownTwoValue) {
this.dropDownTwoValue = dropDownTwoValue;
}
public Set<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 Set<SelectItem> getTestDropDownTwo() {
return testDropDownTwo;
}
public void setTestDropDownTwo(List<SelectItem> testDropDownTwo) {
}
public void setTestDropDown(Set<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";
}
public void changeDropDownOne() {
System.out.println("^^^"+getDropDownTwoValue()+"^^^^^");
String dropDownTwoValueTempValue = getDropDownTwoValue();
String dp = getDropDownValue();
if(dp != null) {
System.out.println("kggggggggggggggggggggggggggggggggggggggggetTestDropDownTwo********************************"+dp);
if(dp.equalsIgnoreCase("One")) {
testDropDownTwo = new HashSet<SelectItem>();
if(dropDownTwoValueTempValue!=null && !dropDownTwoValueTempValue.equalsIgnoreCase("****select***")) {
testDropDownTwo.add(new SelectItem(dropDownTwoValueTempValue));
} else {
testDropDownTwo.add(new SelectItem("****select***"));
}
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 = new HashSet<SelectItem>();
if(dropDownTwoValueTempValue!=null && !dropDownTwoValueTempValue.equalsIgnoreCase("****select***")) {
testDropDownTwo.add(new SelectItem(dropDownTwoValueTempValue));
} else {
testDropDownTwo.add(new SelectItem("****select***"));
}
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("Three")) {
testDropDownTwo = new HashSet<SelectItem>();
if(dropDownTwoValueTempValue!=null && !dropDownTwoValueTempValue.equalsIgnoreCase("****select***")) {
testDropDownTwo.add(new SelectItem(dropDownTwoValueTempValue));
} else {
testDropDownTwo.add(new SelectItem("****select***"));
}
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 = new HashSet<SelectItem>();
if(dropDownTwoValueTempValue!=null && !dropDownTwoValueTempValue.equalsIgnoreCase("****select***")) {
testDropDownTwo.add(new SelectItem(dropDownTwoValueTempValue));
} else {
testDropDownTwo.add(new SelectItem("****select***"));
}
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;
}
}
XHTML代码:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<h:outputScript name="jsf.js" library="javax.faces"/>
</h:head>
<body>
<h:form>
<h:selectOneMenu id="dropDownValue" value="#{loginBean.dropDownValue}" >
<f:selectItem itemValue="****select***" />
<f:selectItems value="#{loginBean.testDropDown}"/>
<f:ajax render="testDropDownTwo" listener="#{loginBean.changeDropDownOne}" />
</h:selectOneMenu>
<h:selectOneMenu id="testDropDownTwo" value="#{loginBean.dropDownTwoValue}" >
<f:selectItem itemValue="****select***" />
<f:selectItems value="#{loginBean.testDropDownTwo}" />
</h:selectOneMenu>
</h:form>
</body>
</html>
在我的办公室系统中,当我更改第一个下拉菜单时,控件将更改为DropDownOne并且testDropDownTwo正在更新,但该值不会反映第二个下拉列表。
请帮助我完成他的regrard
由于
KK