jsf:selectonemenu没有获得最后一个值

时间:2013-07-12 08:45:40

标签: jsf primefaces

每当我从下拉列表中选择最后一个值(选项12 )时,它始终显示第一个选项。除此之外它工作正常。如果我删除该行

<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 PAGE CODE

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

1 个答案:

答案 0 :(得分:0)

尝试将f:selectItem更改为以下其中一个:

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

<f:selectItem itemValue="#{null}" itemLabel="Select One Option" 
    noSelectionOption="true"/>