Select All values
Hi
I am new Jsf
I've question how to select all values from SelectManyListbox through a
button.
I could able to add and remove values to SelectmanyListbox through inputTex but at the same time I want to select all values on a button click
could anybody please explain me how to do this with small example.
any help is appreciated.
Thanks in advance
# 5
<h:selectManyListbox value="#{myBean.selectedItems}">
<f:selectItems value="#{myBean.selectItems}" />
</h:selectManyListbox>
<h:commandButton value="select all" action="#{myBean.selectAllItems}" />
private List < T > selectedItems;
private List < SelectItem < T, String > > selectItems;
// + getters + setters
public void selectAllItems() {
if (selectedItems == null) {
selectedItems = new ArrayList < T >;
} else {
selectedItems.clear();
}
for (SelectItem selectItem : selectItems) {
selectedItems.add(selectItem.getValue());
}
}