我从编译器收到奇怪的错误:
Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectOne(siachoice). Found javax.faces.component.UISelectItems.
因此,如果他期待UISelectItems并找到UISelectItems,那么错误在哪里?
我的JSP实现:
<h:selectOneMenu id="siachoice" value="#{dbSelectBean.currentOption}">
<f:selectItems value="#{dbSelectBean.dbs}" />
</h:selectOneMenu>
我将UISelectItem设置为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;
}
然后,当然,我将其设置为bean变量dbs。
救命?
最佳答案
您必须返回Collection
的javax.faces.model.SelectItem
列表列表= new ArrayList();
list.add(new SelectItem(value,label));
返回清单;