我想在一个中使用枚举值<h:selectManyCheckbox>
.正确填充复选框,但是,在选择某些值并提交它们时,它们的运行时类型是String
,而不是枚举.我的代码:
<h:selectManyCheckbox value="#{userController.roles}" layout="pageDirection">
<f:selectItems value="#{userController.rolesSelectMany}" />
</h:selectManyCheckbox>
Run Code Online (Sandbox Code Playgroud)
UserController类(SecurityRole是枚举类型):
public SelectItem[] getRolesSelectMany() {
SelectItem[] items = new SelectItem[SecurityRole.values().length];
int i = 0;
for (SecurityRole role : SecurityRole.values()) {
items[i++] = new SelectItem(role, role.toString());
}
return items;
}
public List<SecurityRole> getRoles() {
getCurrent().getRoles();
}
public void setRoles(List<SecurityRole> roles) {
getCurrent().setRoles(roles);
}
Run Code Online (Sandbox Code Playgroud)
当JSF调用setRoles方法时,它包含String类型的列表,而不是枚举类型.有任何想法吗?谢谢!