0

每当我从下拉列表中选择最后一个值(OPTION 12)时,它总是显示第一个选项。除此之外它工作正常。如果我删除这条线

<f:selectItem itemValue="0" noSelectionOption="true" itemLabel="Select One Option" />

它工作正常。

任何人都可以给出一些解释,以便我可以让它工作,包括上面的行。

托管豆

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>
4

1 回答 1

0

尝试将 f:selectItem 更改为以下之一:

<f:selectItem itemLabel="Select One Option" 
    noSelectionOption="true"/>

<f:selectItem itemValue="#{null}" itemLabel="Select One Option" 
    noSelectionOption="true"/>
于 2013-07-12T09:21:27.760 回答