在h:selectManyCheckbox中使用枚举

我想在中使用枚举值<h:selectManyCheckbox>。复选框已正确填充,但是,选择一些值并提交时,其运行时类型为String,而不是枚举。我的代码:


<h:selectManyCheckbox value="#{userController.roles}" layout="pageDirection">

     <f:selectItems value="#{userController.rolesSelectMany}" />

</h:selectManyCheckbox>

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);

}

当JSF调用setRoles方法时,它包含String类型的列表,而不是enum类型的列表。有任何想法吗?谢谢!


慕仙森
浏览 352回答 3
3回答

潇潇雨雨

在某些情况下,List也可能是SomeType []数组,在这种情况下,不需要显式转换器。泛型擦除是一种将泛型放入语言而又不破坏旧内容的聪明方法,但是现在我们永远活着这个决定的后果...
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript