Jsf 如何从服务器生成SelectManyCheckbox(primefaces)?

Jsf 如何从服务器生成SelectManyCheckbox(primefaces)?,jsf,primefaces,Jsf,Primefaces,我需要从服务器动态生成一些组件,SelectManyCheckbox有问题。我需要向其中添加selectitems列表,但没有可用的方法。也许有人能帮我,也许我选择了错误的方向。 例如: SelectManyCheckbox checkbox = new SelectManyCheckbox(); List<SelectItem> items SelectManyCheckbox复选框=新建SelectManyCheckbox(); 清单项目 items-必须显示为selectI

我需要从服务器动态生成一些组件,SelectManyCheckbox有问题。我需要向其中添加selectitems列表,但没有可用的方法。也许有人能帮我,也许我选择了错误的方向。 例如:

SelectManyCheckbox checkbox = new SelectManyCheckbox();
List<SelectItem> items
SelectManyCheckbox复选框=新建SelectManyCheckbox();
清单项目

items-必须显示为selectItems的列表。

如果我理解正确,您希望以编程方式添加它们。关键是将它们作为子项添加。一种方法是:

List<SelectItem> items; //Your items
SelectManyCheckbox checkbox = new SelectManyCheckbox();
UISelectItems selectItems = new UISelectItems();
selectItems.setValue(items);
checkbox.getChildren().add(selectItems);
列表项//您的物品
SelectManyCheckbox复选框=新建SelectManyCheckbox();
UISelectItems selectItems=新建UISelectItems();
选择items.setValue(项目);
checkbox.getChildren().add(selectItems);

那么方法setSelectedValues呢?如我所见,作为其中的参数,必须有一个数组。我将selectItems数组放在那里,但id不起作用。@Viktoria它应该是一个值数组(无论与SelectItem值匹配的是什么,例如字符串),而不是selectItems数组。在我的例子中,它是一个双精度列表。用这种方法处理像Double[]这样的数组不起作用吗?也许您应该添加另一个包含所有代码和具体细节的问题:)
import javax.faces.model.SelectItem;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.List;

@ViewScoped
@Named
public class Bean {

    public List<SelectItem> getItems() {
        return new ArrayList<>();
    }
}
List<SelectItem> items; //Your items
SelectManyCheckbox checkbox = new SelectManyCheckbox();
UISelectItems selectItems = new UISelectItems();
selectItems.setValue(items);
checkbox.getChildren().add(selectItems);