1

There are many situations when we want to tell the user to select an option from a selectOneMenu component. In Seam this is easily solved using noSelectionLabel.

<h:selectOneMenu value="#{seasonHome.id}">
        <s:selectItems value="#{seasonListQuery.resultList}"
                       var="season"
                       label="xxxSeason #{season.startYear}"
                       noSelectionLabel="Select Season"
                       hideNoSelectionLabel="true" />
        <s:convertEntity /> 
</h:selectOneMenu>

Can you please tell me if there is something similar in JSF 1.2?

I'm using icefaces with a list for selectItems like:

<ice:selectOneMenu
            id="#{id}"
            required="#{required}"
            styleClass="#{styleClass} #{not required ? 'graNotRequired':''}"
            style="width: #{width};font-size: #{fontSize};"
            partialSubmit="#{partialSubmit}"
            disabled="#{disabled}"
            value="#{fieldOneDataHolder[fieldTwo]}">
            <f:selectItems value="#{selectableItems}" />
            <f:validator validatorId="#{validatorId}" />
        </ice:selectOneMenu>

(please ignore parameters, this is a custom component I made).

I can introduce a new <f:selectItem itemLabel="Please select" itemValue=""/> above f:selectItems but this is difficult (I have to find a way to hide it in some cases etc)...

Do you know other work-around?

Thanks.

Cristian Boariu
  • 9,603
  • 14
  • 91
  • 162

1 Answers1

-1
<f:selectItem itemLabel="Please select" itemValue="" itemDisabled="true" rendered="#{isShown}" />

The itemDisabled will make it shown but not selectable.

The boolean in rendered will decide whether the item is shown or not.

Foumpie
  • 1,465
  • 1
  • 14
  • 10
  • Are you sure that `rendered` attribute is present in jsf 1.2? I do not see it here: http://download.oracle.com/javaee/5/javaserverfaces/1.2/docs/tlddocs/ – Cristian Boariu Jul 20 '11 at 12:00
  • Sorry, my bad. I should've paid better attention. The only way to fix it, i guess, is to bind the items to a backing bean. – Foumpie Jul 20 '11 at 12:16