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>
빈의 생성자 또는 @PostConstruct
메소드에서 DB의 항목을로드 할 수 있습니다.
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