views:

11

answers:

1

Hi!! I wish to set items from a list to the selectonemenu in icefaces. But when I do the same I get the following error: java.lang.ClassCastException: cannot be cast to javax.faces.model.SelectItem

The is an entity class.

Please Help.

+1  A: 

The normal way of creating and populating the selectOneMenu items would be the following:

private String selectedItem; // +getter +setter
private List<SelectItem> selectItems; // +getter

public Bean() {
    selectItems = new ArrayList<SelectItem>();
    for (Entity entity : getYourEntities()) {
        selectItems.add(new SelectItem(entity.getValue(), entity.getLabel()));
    }
}

With the following in the view (you can easily subsitite <h: with <ice:):

<h:selectOneMenu value="#{bean.selectedItem}">
    <f:selectItems value="#{bean.selectItems}" />
</h:selectOneMenu>

Instead of a String value, you can also use any Number (Integer, Long, etc) since JSF has builtin converters for this. But if you want to use whole objects as item value, then you need to create a Converter. This is described in detail in this article.

BalusC