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からBeanのコンストラクタまたは@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