我想在中使用枚举值<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 []数组,在这种情况下,不需要显式转换器。
泛型擦除是一种将泛型放入语言而又不破坏旧内容的聪明方法,但是现在我们永远活着这个决定的后果...
添加回答
举报
0/150
提交
取消