1
<h:selectOneMenu id="reportType" style="width:175px" value="#{pageDemoSearchBean.status}">
    <f:selectItems value="#{pageDemoSearchBean.vehicleStatus}" />
</h:selectOneMenu>

I am using JSF 1.2

This lines of code throws a classCastException

java.lang.String cannot be cast to javax.faces.model.SelectItem

Provided that replacing "value" by "itemValue" in f:selectItems tag is giving another exception which tells that

itemValue is incorrect for selectItems according to TLD

Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40
Pratik Makune
  • 31
  • 1
  • 7

1 Answers1

2

In JSF 1.x, it is not possible to provide a List<T> as <f:selectItems value>. It only supports List<javax.faces.model.SelectItem>.

Here's a kickoff example of proper usage, copypasted from our  tag wiki page (which is written with JSF 2.x in mind, so take into account that some examples won't work for the jurassic JSF 1.x):

<h:form>
    <h:selectOneMenu value="#{bean.selectedItem}">
        <f:selectItem itemValue="#{null}" itemLabel="-- select one --" />
        <f:selectItems value="#{bean.availableItems}" />
    </h:selectOneMenu>
    <h:commandButton value="Submit" action="#{bean.submit}" />
</h:form>
private String selectedItem; // +getter +setter
private List<SelectItem> availableItems; // +getter (no setter necessary)

@PostConstruct
public void init() {
    availableItems = new ArrayList<SelectItem>();
    availableItems.add(new SelectItem("foo", "Foo label"));
    availableItems.add(new SelectItem("bar", "Bar label"));
    availableItems.add(new SelectItem("baz", "Baz label"));
}
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555