I am facing one issue with selectOneMenu. I need to display list of items in a drop down and it is a required field.
In that drop down the first value is "Select". If the user doesn't select any question, then I need to display an error message like "Select any question".
Can anyone give me solution?
Just set the item value of the first item to null. You shouldn't set it with the value of the label.
E.g.
<h:selectOneMenu value="#{bean.question}" required="true" requiredMessage="Please select a question">
<f:selectItem itemValue="#{null}" itemLabel="Select" />
<f:selectItems value="#{bean.questions}" />
</h:selectOneMenu>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With