I am trying to building a drop down menu using JSF 2.0,
and add a validation when the use submit the form with “Please Select” selected in the menu.
<h:selectOneMenu id="templateMenu" value="#{bean.list}" required="true" requiredMessage="Please select a value.">
<f:selectItem itemLabel="Please Select" noSelectionOption="true" />
<f:selectItem itemLabel="Item01" itemValue="1"/>
<f:selectItem itemLabel="Item02" itemValue="2"/>
<f:selectItem itemLabel="Item03" itemValue="3"/>
<f:selectItem itemLabel="Item04" itemValue="4"/>
<f:validateRequired/>
</h:selectOneMenu>
However when I submit the page with “Please Select” selected, the validation doesn’t fire, it just stay in the same page.
If anyone know what’s happening please could you help me?
Thanks a lot!!
You need
h:messagefor your selectOneMenu. Which will display the message ofrequiredMessageofselectOneMenu.