为了账号安全,请及时绑定邮箱和手机立即绑定

在h:selectManyCheckbox中使用枚举

在h:selectManyCheckbox中使用枚举

慕仙森 2019-11-18 13:55:52
我想在中使用枚举值<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类型的列表。有任何想法吗?谢谢!
查看完整描述

3 回答

?
潇潇雨雨

TA贡献1833条经验 获得超4个赞

在某些情况下,List也可能是SomeType []数组,在这种情况下,不需要显式转换器。

泛型擦除是一种将泛型放入语言而又不破坏旧内容的聪明方法,但是现在我们永远活着这个决定的后果...


查看完整回答
反对 回复 2019-11-18
  • 3 回答
  • 0 关注
  • 351 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号