[英]How to generate SelectManyCheckbox (primefaces) from the server?
I need to generate dynamically some components from the server and I have a problem with SelectManyCheckbox. 我需要从服务器动态生成一些组件,并且SelectManyCheckbox出现问题。 I need to add a list of selectitems into it but there is no such method available. 我需要在其中添加selectitems列表,但是没有可用的方法。 Maybe someone can help me, maybe I choose wrong direction. 也许有人可以帮助我,也许我选择了错误的方向。 Example: 例:
SelectManyCheckbox checkbox = new SelectManyCheckbox();
List<SelectItem> items
items - the list that must be displayed as selectItems. items-必须显示为selectItems的列表。
If I understood you correctly, you want to add them programmatically. 如果我对您的理解正确,则需要以编程方式添加它们。 The key is to add them as children. 关键是将它们添加为子代。 One way to do it could be like this: 一种方法是这样的:
List<SelectItem> items; //Your items
SelectManyCheckbox checkbox = new SelectManyCheckbox();
UISelectItems selectItems = new UISelectItems();
selectItems.setValue(items);
checkbox.getChildren().add(selectItems);
The value
of <f:selectItems
of a <p:selectManyCheckbox
can be populated with objects of SelectItem
: <p:selectManyCheckbox
的<f:selectItems
的value
可以用SelectItem
对象填充:
Value expression pointing at any
Collection
or array. 指向任何Collection
或数组的值表达式。 The member elements may be instances ofSelectItem
or any Java Object. 成员元素可以是SelectItem
实例或任何Java对象。
<p:selectManyCheckbox>
<f:selectItems value="#{bean.items}"/>
</p:selectManyCheckbox>
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<>();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.