好吧,我一直堅持這一兩天(輕描淡寫)。JSF ValueChangeEvent:如何根據我在之前的SelectOneMenu上的選擇更改一個SelectOneMenu上的選項?
說我有一個selectOneMenu用於
<h:selectOneMenu id="selectFamily" valueChangeListener="#{menuBean.changeFamily}" onclick="submit()" immediate="true" > <f:selectItems id="familyNames" value="#{menuBean.familyNames}" /> </h:selectOneMenu>
而且我想改變基於這個以前selectOneMenu用於選擇 的選項上的另一個selectOneMenu用於選項。
<h:selectOneMenu id="selectFunction" immediate="true"> <f:selectItems id="functions" value="#{menuBean.functions}" /> </h:selectOneMenu>
我如何做到這一點?讀書的時候,我有一對夫婦的如何做到這一點的想法,但我似乎無法得到它的權利。我很抱歉,我只是在這裏傾倒豆類,希望有人能指導我。
公共類MenuBean使用{
/** Creates a new instance of MenuBean */
public MenuBean() {
}
private SelectItem[] familyNames = {
new SelectItem((Integer) 1,"Operations"),
new SelectItem((Integer) 2, "Special"),
new SelectItem((Integer) 3, "Support")};
public SelectItem[] getFamilyNames() {
return familyNames;
}
private SelectItem[] functions = {new SelectItem("Select Function")};
private SelectItem[] operationsFunctions = {
new SelectItem("Air/Ocean Freight"),
new SelectItem("Customs"),
new SelectItem("Land Transport"),
new SelectItem("Logistics/SCM"),
new SelectItem("Rail Transport"),
new SelectItem("Special")
};
private SelectItem[] specialFunctions = {
new SelectItem("General Management"),
new SelectItem("Quality & Processes")
};
private SelectItem[] supportFunctions = {
new SelectItem("Finance/Controlling"),
new SelectItem("Human Resources"),
new SelectItem("ICT"),
new SelectItem("Legal Affairs"),
new SelectItem("Marketing/Public Relations"),
new SelectItem("Procurement"),
};
public SelectItem[] getFunctions(int n) {
if (n==1) {
functions = operationsFunctions;
} else if (n==2) {
functions = specialFunctions;
} else if (n==3) {
functions = supportFunctions;
}
return functions;
}
public void setFunctions(SelectItem[] function) {
this.functions = function;
}
public void changeFamily(ValueChangeEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
int value = (Integer) event.getNewValue();
setFunctions(getFunctions(value));
context.renderResponse();
}}
您是否使用JSF1.2或2? – Dejell 2010-08-12 05:33:21
我使用JSF 2. – 2010-08-12 06:56:04