我创建了一个SelectOneMenu uicomponent。
SelectOneMenu value = new SelectOneMenu();
我想在SelectOneMenu中插入一些selectItems.我试过这样做。
String[] options = question.getOptions().split(",");
for(String option : options){
SelectItem selectItem = new SelectItem();
selectItem.setLabel(option);
selectItem.setValue(option);
value.getChildren().add(selectItem);
}
但是当我添加selectItem时,我得到错误信息,说add(uicomponent)不适用于参数SelectItem。该怎么办,有什么建议吗?
但是它失败了,因为 javax.faces.model.SelectItem
不是 UIComponent
. 你应该有的是 UISelectItem
. 所以你的代码应该更像
String[] options = question.getOptions().split(",");
for(String option : options){
UISelectItem selectItem = new UISelectItem();
selectItem.setItemLabel(option);
selectItem.setItemValue(option);
value.getChildren().add(selectItem);
}