2013-07-12 30 views
0

每當我從下拉菜單中選擇上一個值(選項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> 
+0

選擇其他選項11,10。 ..等工作正常? – fareed

+0

@ ed yes yes可以和其他選項一起使用。 – mrugeshthaker

+0

基於[鏈接](http://stackoverflow.com/questions/14110755/pselectonemenu-preselects-previous-item-when-noselectionoption-item-is-present)。我已經嘗試過,並且我取得了成功。 ** itemValue =「」**或** itemValue =「#{null}」** without ** noSelectionOption **和required = true正常。 – mrugeshthaker

回答

0

嘗試改變F:選擇信息爲這些類型之一:

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

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

我已經嘗試了這兩個選項,但沒有奏效。但是我發現一件可悲的事情是,如果我刪除** noSelectionOption **,那麼它適用於所有選項(即從1到12)。你能告訴我selectOneMenu中** noSelectionOption有什麼問題嗎? – mrugeshthaker

+0

你可以嘗試使用h:selectOneMenu代替p:selectOneMenu並告訴我這是否有效? –

+0

我嘗試了你的建議,它工作正常。另請查看[BalusC](http://stackoverflow.com/questions/14110755/pselectonemenu-preselects-previous-item-when-noselectionoption-item-is-present)文章。我嘗試過工作。 – mrugeshthaker