0
我想知道如何填充數據庫中的h:selectManyListbox
,即不能使用靜態選項。如何從數據庫填充selectManyListbox
我想知道如何填充數據庫中的h:selectManyListbox
,即不能使用靜態選項。如何從數據庫填充selectManyListbox
使用<f:selectItems>
結合使用返回List<SelectItem>
的屬性,或者當您已經使用JSF 2.0時,使用List<SomeObject>
。
<h:selectManyListbox value="#{bean.selectedItems}">
<f:selectItems value="#{bean.selectItems}" />
</h:selectManyListbox>
您可以從DB的構造函數或@PostConstruct
方法中加載項目。
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
}
@BalusC的回答是否令您滿意? – Damian 2011-09-28 05:24:35