Jsf 如何从数据库中填充SelectManyList框
我想知道如何从数据库中填充Jsf 如何从数据库中填充SelectManyList框,jsf,Jsf,我想知道如何从数据库中填充h:selectManyListbox,即不使用静态选项。将与返回列表的属性结合使用,或者当您已经使用JSF 2.0时,使用列表 @BalusC的回答是否令您满意? <h:selectManyListbox value="#{bean.selectedItems}"> <f:selectItems value="#{bean.selectItems}" /> </h:selectManyListbox> public cla
h:selectManyListbox
,即不使用静态选项。将
与返回列表的属性结合使用,或者当您已经使用JSF 2.0时,使用列表
@BalusC的回答是否令您满意?
<h:selectManyListbox value="#{bean.selectedItems}">
<f:selectItems value="#{bean.selectItems}" />
</h:selectManyListbox>
public class Bean {
private List<String> selectedItems;
private List<SelectItem> selectItems;
public Bean() {
selectItems = new ArrayList<SelectItem>();
// Fill select items during Bean initialization/construction.
// Below is just an example, you could replace this by getting a list
// of some objects from DB and creating new items in a loop.
selectItems.add(new SelectItem("value1", "label1"));
selectItems.add(new SelectItem("value2", "label2"));
selectItems.add(new SelectItem("value3", "label3"));
}
// Getters, etc
}