如何以af:selectManyCheckbox
编程方式设置项目的选择?
我有一个旧 ADF 版本,我尝试在此列表中创建一个项目,如果我单击它,它将选择所有剩余的项目:
<af:selectManyCheckbox value="#{usersByRoleFBB.selectedRolesId}"
valueChangeListener="#{usersByRoleFBB.listChanged}"
required="true" showRequired="true" label="Роли: ">
<f:selectItems value="#{usersByRoleFBB.listRoleItems}" />
</af:selectManyCheckbox>
我的java类:
private List<SelectItem> listRoleItems;
private Long[] selectedRolesId;
public void listChanged(ValueChangeEvent event) {
Long oldValue = (Long) event.getOldValue();
Long newValue = (Long) event.getNewValue();
if (oldValue == -1 || newValue == -1) {
if (newValue == -1L) {
for (SelectItem selectItem : listRoleItems) {
selectItem.setValue(true);
}
}
if (oldValue == -1L) {
for (SelectItem selectItem : listRoleItems) {
selectItem.setValue(false);
}
}
}
}