从下拉框中选择一个值并在下拉框中调用 valueChangeListener 后,我想预先检查多个复选框。以下是代码:
在 JSF 页面中:
<h:selectOneMenu id="roleName" styleClass="text" value="#{role.roleID}" valueChangeListener="#{role.processValueChange}" immediate="true" onchange="submit()">
<f:selectItem itemLabel="--Select--" itemValue="--Select--"></f:selectItem>
<f:selectItems noSelectionValue="--Select--" value="#{role.rolesVoList}" var="x" itemLabel="#{x.roleName}" itemValue="#{x.roleID}" />
</h:selectOneMenu>
<p>
<h:outputText value="Notifications" styleClass="label" />
</p>
<p>
<h:selectManyCheckbox id="notificationPrivileges" value="#{role.notificationPrivileges}" layout="pageDirection">
<f:selectItems value="#{role.notificationPrivilegeMap}" />
</h:selectManyCheckbox>
</p>
在托管 Bean 中:
private List<RolesVo> rolesVoList;
private boolean checkBoxSet = false;
private List<Integer> notificationPrivileges;
private Map<String, Integer> notificationPrivilegeMap;
private RolePrivilegeVo rolePrivilege;
public void processValueChange(ValueChangeEvent event) {
messageHandler = new MessageHandler();
int newValue = (Integer) event.getNewValue();
setRoleID(newValue);
try {
rolePrivilege = roleService.getRolePrivileges(newValue);
setNotificationPrivileges(rolePrivilege.getPrivilegeIDs());
setCheckBoxSet(true);
} catch (Exception e) {
messageHandler.addGlobalErrorMessage(OATSConstants.errorFetchPrivilege);
}
}
getPrivilegeIDs() 返回整数列表。正在提交表单并且正在成功处理 valueChangeListener 方法,但之后未选中复选框。请指出我做错了什么。非常感谢任何帮助。