gpt4 book ai didi

jsf-2 - 如何在 jsf 中获取多选复选框值?

转载 作者:行者123 更新时间:2023-12-01 22:18:01 25 4
gpt4 key购买 nike

我已经创建了复选框。当我选择多个复选框时,我怎样才能获得那些多个选中的复选框值?我的代码是:

<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>

我采用了 value="#{adcreateBean.editionID}",因此它返回单个值。

最佳答案

value<h:selectManyXxx>组件需要指向一个数组或ListitemValue 属于同一类型.假设它是 Long , 然后它需要绑定(bind)到 Long[]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>

如果您喜欢 List<Long> , 那么你应该明确地为 Long 提供一个转换器类型,因为泛型类型在运行时被删除,没有转换器 EL 将设置 String List 中的值这最终只会导致 ClassCaseException秒。因此:

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>

关于jsf-2 - 如何在 jsf 中获取多选复选框值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11065427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com