每當我從下拉菜單中選擇上一個值(選項12)時,它總是顯示第一個選項。除此之外,它工作正常。如果我刪除硫線jsf:selectonemenu沒有得到上一個值
<f:selectItem itemValue="0" noSelectionOption="true" itemLabel="Select One Option" />
它工作正常。
有人可以給一些解釋,以便我可以得到它的工作,包括上線。
ManagedBean
public class ReportUitility implements java.io.Serializable {
private List<SelectItem> list = null;
public ReportUitility() {
reportType = "0";
list = new ArrayList<SelectItem>();
list.add(new SelectItem("1","OPTION 1"));
list.add(new SelectItem("2","OPTION 2"));
list.add(new SelectItem("3","OPTION 3"));
list.add(new SelectItem("4","OPTION 4"));
list.add(new SelectItem("5","OPTION 5"));
list.add(new SelectItem("6","OPTION 6"));
list.add(new SelectItem("7","OPTION 7"));
list.add(new SelectItem("8","OPTION 8"));
list.add(new SelectItem("9","OPTION 9"));
list.add(new SelectItem("10","OPTION 10"));
list.add(new SelectItem("11","OPTION 11"));
list.add(new SelectItem("12","OPTION 12"));
}
public List<SelectItem> getList() {
return list;
}
public String getReportType() {
return reportType;
}
public void setReportType(String reportType) {
this.reportType = reportType;
}
public void valueChangeEffect(ValueChangeEvent vce) {
if ((Integer.parseInt(vce.getNewValue().toString()) - 1) >= 7) {
//some stuff
} else {
// some stuff
}
}
}
JSF頁面代碼
<p:selectOneMenu id="selectReportType" required="true" value="#{reportUitility.reportType}" valueChangeListener="#{reportUitility.valueChangeEffect}">
<f:selectItem itemValue="0" noSelectionOption="true" itemLabel="Select One Option" />
<f:selectItems value="#{reportUitility.list}" />
<p:ajax event="change" update="selectReportType,gradeFrom,gradeTo,exportToXLS,exportToText"/>
</p:selectOneMenu>
選擇其他選項11,10。 ..等工作正常? – fareed
@ ed yes yes可以和其他選項一起使用。 – mrugeshthaker
基於[鏈接](http://stackoverflow.com/questions/14110755/pselectonemenu-preselects-previous-item-when-noselectionoption-item-is-present)。我已經嘗試過 ,並且我取得了成功。 ** itemValue =「」**或** itemValue =「#{null}」** without ** noSelectionOption **和required = true正常。 –
mrugeshthaker