views:

237

answers:

3

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?

A: 

The problem is UISelectItem is a component clas so it has to be paired with jsf tag by binding attribute. If you want to have pure values you have to use SelectItem(s) classes.

cetnar
+2  A: 
Bozho
Any examples, please?
Yurish
Check the updated post
Bozho
It works, thanks!
Yurish
+1  A: 

The <f:selectItems value="#{bean.items}" /> expects one of the following values:

public SelectItem[] getItems() {}

public List<SelectItem> getItems() {}

public Map<String, Object> getItems() {}

The commonly used one is indeed the List<SelectItem>.

Edit: as response to the comment: UISelectItem represents the <f:selectItem> component. The same applies to UISelectItems and <f:selectItems>. E.g.

<f:selectItem binding="#{bean.selectItem}" />
<f:selectItems binding="#{bean.selectItems}" />

which are bound as

private UISelectItem selectItem;
private UISelectItems selectItems;
// +getter +setter

this way you can control the components programmatically -as for every other UIComponent.

BalusC
Then what`s the difference between SelectItem and UISelectItem?
Yurish
SelectItem represents the value. UISelectItem represents the Component.
BalusC