Reputation: 270
I have created a SelectOneMenu uicomponent
SelectOneMenu value = new SelectOneMenu();
I want to insert some selectItems in the SelectOneMenu. I tried this
String[] options = question.getOptions().split(",");
for(String option : options){
SelectItem selectItem = new SelectItem();
selectItem.setLabel(option);
selectItem.setValue(option);
value.getChildren().add(selectItem);
}
But when i add the selectItem i am getting error that add(uicomponent) is not applicable for arguments SelectItem. What to do, any suggestions?
Upvotes: 0
Views: 573
Reputation: 20691
Well it's failing because javax.faces.model.SelectItem
is not a UIComponent
. What you should have is the UISelectItem
. So your code should look more like
String[] options = question.getOptions().split(",");
for(String option : options){
UISelectItem selectItem = new UISelectItem();
selectItem.setItemLabel(option);
selectItem.setItemValue(option);
value.getChildren().add(selectItem);
}
Upvotes: 4