Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show required message of h:selectOneMenu with a default select option?

Tags:

jsf-2

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?

like image 974
Raj Avatar asked Aug 17 '11 11:08

Raj


1 Answers

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>
like image 182
BalusC Avatar answered Jan 02 '23 19:01

BalusC