相关疑难解决方法(0)

在h:selectManyCheckbox中使用enum

我想在一个中使用枚举值<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类型的列表,而不是枚举类型.有任何想法吗?谢谢!

jsf enums jsf-2 selectmanycheckbox

20
推荐指数
1
解决办法
2万
查看次数

标签 统计

enums ×1

jsf ×1

jsf-2 ×1

selectmanycheckbox ×1