从服务器端创建SelectOneMenu UIComponent。

问题描述 投票:0回答:1

我创建了一个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。该怎么办,有什么建议吗?

jsf-2 primefaces
1个回答
4
投票

但是它失败了,因为 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);
}
© www.soinside.com 2019 - 2024. All rights reserved.