复选框ArrayList抛出PropertyNotWritableException

时间:2019-01-09 06:01:50

标签: java jsf primefaces

当我尝试将复选框的布尔值设置为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”。我认为它会使用get(0)而不是set(0,something)抛出am的bcz。默认情况下,它必须获取get(0)所以false因此未经检查。如果用户想要更改,则必须将其设置为true因此进行检查。

1 个答案:

答案 0 :(得分:0)

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

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

有关如何使用这些功能的更多信息,请参阅PrimeFaces展示柜;请参阅。 https://www.primefaces.org/showcase/ui/input/oneRadio.xhtml https://www.primefaces.org/showcase/ui/input/manyCheckbox.xhtml