0

Whenever I select last value (OPTION 12) from dropdown it always show first option. Other than that it work fine. IF I remove thi line

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

it works fine.

Can anybody give some explaination so that i can get it work including above line.

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>
mrugeshthaker
  • 657
  • 2
  • 8
  • 25
  • Selecting other options 11 , 10 ... etc work fine? – fareed Jul 12 '13 at 08:59
  • @fareed yes it works well with other options. – mrugeshthaker Jul 12 '13 at 10:34
  • on th basis of [link](http://stackoverflow.com/questions/14110755/pselectonemenu-preselects-previous-item-when-noselectionoption-item-is-present). I have tried and i got sucess. **itemValue=""** or **itemValue="#{null}"** without **noSelectionOption** and required=true works fine. – mrugeshthaker Jul 12 '13 at 10:55

1 Answers1

0

Try changing the f:selectItem to one of these:

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

<f:selectItem itemValue="#{null}" itemLabel="Select One Option" 
    noSelectionOption="true"/>
Emil Kaminski
  • 1,886
  • 2
  • 16
  • 26
  • I have tried both option but not worked. But I found one miserable thing is, If I remove **noSelectionOption** then it works for all option (i.e. from 1 to 12). Can you tell me what is wrong with **noSelectionOption** in selectOneMenu. – mrugeshthaker Jul 12 '13 at 10:36
  • Could you try using a h:selectOneMenu instead of p:selectOneMenu and tell me if that worked? – Emil Kaminski Jul 12 '13 at 11:03
  • I have tried as you suggested and it's working fine. Also please look into the [BalusC](http://stackoverflow.com/questions/14110755/pselectonemenu-preselects-previous-item-when-noselectionoption-item-is-present) post. I have tried got working. – mrugeshthaker Jul 12 '13 at 11:36