他のドロップダウンの値が変更されたときに、ドロップダウン リストにデータを入力しようとしています。つまり、一般的な例: 国と都市。これには f:ajax を試しました。ajax 呼び出しは行われていますが、都市のドロップダウンにはデータが入力されていません。
マネージド Bean コード自体に問題がありますが、見つかりません。誰か見てもらえますか?
register.xhtml
<h:selectOneMenu id="state" value="#{registerBean.state}" required="true">
<f:selectItems value="#{registerBean.stateList}"/>
<f:ajax render="outputDrop city" listener="#{registerBean.cityListener}"/>
</h:selectOneMenu>
<h:message for="state" />
<h:outputText id="outputDrop" value="#{registerBean.state}" />
<h:outputText value="#{msgbundle.reg_city}" />
<h:selectOneMenu id="city" value="#{registerBean.city}" required="true">
<f:selectItems value="#{registerBean.cityList}" />
</h:selectOneMenu>
<h:message for="city" />
ManagedBean
package org.droidaceapps.contractortimeflow;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.model.SelectItem;
public class RegUserInfoBean {
private String userName;
private String city;
private String state;
private String phone;
private String sex;
private ArrayList<SelectItem> stateList;
private ArrayList<SelectItem> cityList;
private enum stateKeys {AP,TN,MH};
public ArrayList<SelectItem> getStateList(){
stateList = new ArrayList<SelectItem>();
stateList.add(new SelectItem(null,"Select state"));
stateList.add(new SelectItem("AP","Andhra Pradesh"));
stateList.add(new SelectItem("TN","Tamilnadu"));
stateList.add(new SelectItem("MH","Maharastra"));
return stateList;
}
public ArrayList<SelectItem> getCityList(){
cityList = new ArrayList<SelectItem>();
cityList.add(new SelectItem(null,"Select"));
return cityList;
}
public void cityListener(AjaxBehaviorEvent event){
switch(stateKeys.valueOf(state)){
case AP:
cityList.add(new SelectItem("VIJ","Vijayawada"));
cityList.add(new SelectItem("GUN","Guntur"));
break;
case MH:
cityList.add(new SelectItem("MUM","Mumbai"));
cityList.add(new SelectItem("PUN","Pune"));
break;
case TN:
cityList.add(new SelectItem("CHE","Chennai"));
cityList.add(new SelectItem("MAD","Madurai"));
break;
default:
cityList.add(new SelectItem("NA","No value"));
}
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}