组件的需要指向一个数组或value与. 假设它是,那么它需要绑定到 a或。<h:selectManyXxx>ListitemValueLongLong[]List<Long>
例如
private Long[] selectedEditionIds; // +getter +setter
private List<Edition> availableEditions; // +getter
和
<h:selectManyCheckbox value="#{bean.selectedEditionIds}">
<f:selectItems value="#{bean.availableEditions}" var="edition" itemLabel="#{edition.name}" itemValue="#{edition.id}" />
</h:selectManyCheckbox>
如果您更喜欢 a List<Long>,那么您应该显式地为该Long类型提供一个转换器,因为泛型类型在运行时会被删除,并且如果没有转换器,EL 会在 中设置String值,List最终只会导致ClassCaseExceptions。因此:
private List<Long> selectedEditionIds; // +getter +setter
private List<Edition> availableEditions; // +getter
和
<h:selectManyCheckbox value="#{bean.selectedEditionIds}" converter="javax.faces.Long">
<f:selectItems value="#{bean.availableEditions}" var="edition" itemLabel="#{edition.name}" itemValue="#{edition.id}" />
</h:selectManyCheckbox>