How to disable Submit button if nothing is selected in Primefaces SelectOneMenu
jsf-2, primefaces
Solution
You better replace
<f:selectItem itemLabel="Please select"/>
With
<f:selectItem noSelectionOption="true" itemLabel="Please select"></f:selectItem>
And let the jsf to handle the `required` for you...
If you really want to disable the button just use the `#{bean.value}`
like this
<p:commandButton id="myButonId" disabled="#{empty bean.value}"....
and add `<p:ajax update="myButonId"` to your `<p:selectOneMenu`
Problem
I have a `p:selectOneMenu` whose first element is a string 'Please select' and other items are a list to be selected. Can I disable the submit button when 'Please select' is selected and enable the button if other elements are selected? I know that `itemDisabled` can be used, but that is not my requirement. ``` <p:selectOneMenu value="#{bean.value}" id="selectId" filter="true" required="true" converter="itemConverter" filterMatchMode="contains" height="120"> <f:selectItem itemLabel="Please select"/> <f:selectItems value="#{listBean.selectItemList}"></f:selectItems> </p:selectOneMenu> ``` Essentially, I want the submit button to be disabled when the first item is selected. Can someone please help?