复选框 ArrayList 抛出 PropertyNotWritableException

Checkbox ArrayList throw PropertyNotWritableException

当我尝试将复选框的布尔值设置为 arraylist 复选框列表元素时,我得到 "PropertyNotWritableException"。

<p:selectBooleanCheckbox value="#{trialBalanceBean.chkBoxList.get(0)}" itemLabel="#{loc.fuelstockcards}">
                                <p:ajax update="frmTrialBalance:fuelStockMenu"/>
                            </p:selectBooleanCheckbox>

 List<Boolean> chkBoxList = Arrays.asList(new Boolean[]{false, true, true, 
 true, true, true, true, true, true, true});

然后我将布尔列表创建为 chkBoxList 当我更改复选框的值时,它会抛出 "PropertyNotWritableException" 。我认为它抛出 bcz of am using get(0) not set(0,something)。默认它必须得到 get(0) 如此错误所以 unchecked.If 用户想要更改它必须设置为 true 所以检查。

这正是您应该期望的行为。布尔值 class 是不可变的,因此无法将其用作支持 bean 值容器。

您在这里应该使用的是 <p:selectManyCheckBox><p:selectOneRadio> 组件。它们专门设计用于处理多项选择和传入的选择项数组。

关于如何使用这些的更多信息,您可以参考PrimeFaces showcase; https://www.primefaces.org/showcase/ui/input/oneRadio.xhtml https://www.primefaces.org/showcase/ui/input/manyCheckbox.xhtml