编辑:
我正在尝试迭代由PrimeFaces的DualListModel带来的用户选择的值的列表。

这是我想做的事情:

List<Department> dptsSelected = dptsDual.getTarget();
for (Department d : dptsSelected ) {
//do something
}


dptsDual:

DualListModel<Department> dptsDual;


进入FOR循环时出现错误。甚至在异常进入循环之前就将其引发,并在FOR处引发该异常。

java.lang.ClassCastException: java.lang.String cannot be cast to Department


TIA

最佳答案

您正在混合两种不同的事物,DepartmentEnum和Department。首先确定您的需求是否需要dptsDual作为Department的DualListModel或DepartmentEnum的DualListModel

现在尝试这种方式……

在xhtml中:

 <p:pickList value="#{myBean.myDepartment}" ....>


在bean中:

List<Department> selectedDepartments = new ArrayList<Department>();
List<Department> availableDepartments = getAvailableDepartments();

private DualListModel<Department> myDepartment;
myDepartment = new DualListModel<Department>(availableDepartments, selectedDepartments);


提交后,selectedDepartments将由用户选择部门

关于java - Java PrimeFaces-DualListModel迭代,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10039678/

10-10 21:53