JSF - UISelectItems problem

Yurish picture Yurish · Nov 13, 2009 · Viewed 8.4k times · Source

Strange error i received from compiler:

Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectOne(siachoice).  Found javax.faces.component.UISelectItems.

So, if he was expecting UISelectItems, and found UISelectItems, then where is the error?

My JSP implementation:

<h:selectOneMenu id="siachoice" value="#{dbSelectBean.currentOption}">
                                <f:selectItems value="#{dbSelectBean.dbs}" />
                            </h:selectOneMenu>

Method, where i am setting UISelectItem to UISelectItems:

private UISelectItems populateDatabases(String databaseString) {
    UISelectItems selects = new UISelectItems();
    List<UISelectItem> result = new ArrayList<UISelectItem>();
    StringTokenizer tokeniz = new StringTokenizer(databaseString, GlobalConstants.DELIMITER);
    while(tokeniz.hasMoreTokens()){
        String tempDB = tokeniz.nextToken();
        UISelectItem item = new UISelectItem();
        item.setItemValue(tempDB);
        item.setItemLabel(tempDB);
        result.add(item);
    }
    selects.setValue(result);

    return selects;
}

Then, of course, i am setting it to the bean variable dbs.

Help?

Answer

Bozho picture Bozho · Nov 13, 2009

You must return a Collection of javax.faces.model.SelectItem

List list = new ArrayList();
list.add(new SelectItem(value, label));

return list;