Tag: selectmanycheckbox

列表<T>上的UISelectMany导致java.lang.ClassCastException:java.lang.String不能转换为T

我正在List<Long>上使用<p:selectCheckboxMenu> List<Long> : <p:selectCheckboxMenu value="#{bean.selectedItems}"> <f:selectItems value="#{bean.availableItems}" /> </p:selectCheckboxMenu> private List<Long> selectedItems; private Map<String, Long> availableItems; 在提交表单并循环显示所选项目时, for (int i = 0; i < selectedItems.size(); i++) { Long id = selectedItems.get(i); // … } 然后我得到一个类抛出exception: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long at com.example.Bean.submit(Bean.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.apache.el.parser.AstValue.invoke(AstValue.java:278) […]

在h:selectManyCheckbox中使用枚举

我想在<h:selectManyCheckbox>使用枚举值。 checkbox会正确填充,但是,在select某些值并提交它们时,它们的运行时types是String ,而不是枚举。 我的代码: <h:selectManyCheckbox value="#{userController.roles}" layout="pageDirection"> <f:selectItems value="#{userController.rolesSelectMany}" /> </h:selectManyCheckbox> UserController类(SecurityRole是一个枚举types): 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方法时,它包含一个Stringtypes的列表,而不是枚举types。 有任何想法吗? […]