Chirag Kawariya
Chirag Kawariya

Reputation: 225

How to remove default option from dropdown list in <h:selectOneMenu>

I am working on a JSF page which has a dropdown based on selectOneMenu

<h:selectOneMenu id="speciality_unit" value="#{editCdc.selectedUnit}">
    <f:selectItem itemValue="" itemLabel="Select Unit" />
    <f:selectItems value="#{editCdc.listOfUnit}" />
</h:selectOneMenu>

The problem I am facing here is that whenever I select this dropdown, it shows the default option in the list along with other items. I.e. it shows "Select Unit" along with other units. I want to remove this "Select Unit" from the dropdown list. How I can do this?

Upvotes: 1

Views: 1166

Answers (1)

BalusC
BalusC

Reputation: 1108722

Hide it using CSS.

<h:selectOneMenu ... styleClass="hideFirstOption">
select.hideFirstOption option:first-child {
    display: none;
}

Upvotes: 3

Related Questions