2014-09-04 65 views
0

创建selectOneMenu用于UIComponent uicomponent从我创建了一个selectOneMenu用于服务器端

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); 
} 

但是,当我加我收到错误添加选择信息(uicomponent)不适用于参数的SelectItem。怎么办,有什么建议?

回答

4

那么它的失败是因为javax.faces.model.SelectItem不是UIComponent。你应该拥有的是UISelectItem。所以你的代码应该看起来更像

String[] options = question.getOptions().split(","); 
for(String option : options){ 
    UISelectItem = new UISelectItem(); 
    selectItem.setItemLabel(option); 
    selectItem.setItemValue(option); 
    value.getChildren().add(selectItem); 
} 
相关问题