How can I get multiselected checkbox value in jsf?
jsf-2
Solution
The `value` of the `<h:selectManyXxx>` component needs to point to an array or `List` of the very same type as the `itemValue`. Assuming that it's `Long`, then it needs to be bound to a `Long[]` or `List<Long>`.
E.g.
private Long[] selectedEditionIds; // +getter +setter
private List<Edition> availableEditions; // +getter
with
<h:selectManyCheckbox value="#{bean.selectedEditionIds}">
<f:selectItems value="#{bean.availableEditions}" var="edition" itemLabel="#{edition.name}" itemValue="#{edition.id}" />
</h:selectManyCheckbox>
If you prefer a `List<Long>`, then you should explicitly supply a converter for the `Long` type, because generic types are erased during runtime and without a converter EL would set `String` values in the `List` which would ultimately only result in `ClassCaseException`s. Thus so:
private List<Long> selectedEditionIds; // +getter +setter
private List<Edition> availableEditions; // +getter
with
<h:selectManyCheckbox value="#{bean.selectedEditionIds}" converter="javax.faces.Long">
<f:selectItems value="#{bean.availableEditions}" var="edition" itemLabel="#{edition.name}" itemValue="#{edition.id}" />
</h:selectManyCheckbox>
Problem
I have created checkboxes. When I selected multiple checkboxes then how can I get those multiple selected checkboxes value? my code is: ``` <h:selectManyCheckbox id="chkedition" value="#{adcreateBean.editionID}" layout="lineDirection" styleClass="nostyle"> <f:selectItems value="#{adcreateBean.editions}" var="item" itemLabel="#{item.editionName}" itemValue="#{item.editionID}"/> </h:selectManyCheckbox> ``` I have taken value="#{adcreateBean.editionID}" ,so it returns single value.