2014-09-04 72 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); 
} 
相關問題