p:使用selectionMode作为多个的数据表

时间:2012-08-06 03:12:22

标签: jsf jsf-2 primefaces

根据primefaces文档,选择应该是一个数组。在下面的代码中,bean.selectedUsers被定义为“HasUsersVO [] selectedUsers”,但是datatable的值是List。当数据表填满后单击“确定”按钮时,我在底部粘贴了转换错误。

                <p:dataTable id="userListTable" value="#{bean.peopleVOList}"
                    var="user" rowClasses="odd even" selection="#{bean.selectedUsers}" rowKey="#{user.userGuid}"
                    <p:column selectionMode="multiple" style="width:18px">
                    </p:column>
.....
.....
</p:dataTable>

错误

22:59:16,962 INFO  [class com.zreflect.emyed.managedbean.circle.CircleController] (http--127.0.0.1-8080-3) *******************Outside getUsersList********************
22:59:38,943 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (http--127.0.0.1-8080-3) [Lcom.user.PeopleVO; cannot be cast to java.util.Collection: java.lang.ClassCastException: [Lcom.user.PeopleVO; cannot be cast to java.util.Collection
    at org.primefaces.component.datatable.DataTable.getRowData(DataTable.java:835) [primefaces-3.3.1.jar:]
    at org.primefaces.component.datatable.DataHelper.decodeMultipleSelection(DataHelper.java:262) [primefaces-3.3.1.jar:]
    at org.primefaces.component.datatable.DataHelper.decodeSelection(DataHelper.java:240) [primefaces-3.3.1.jar:]
    at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:72) [primefaces-3.3.1.jar:]

1 个答案:

答案 0 :(得分:3)

异常消息和堆栈跟踪表明您在PeopleVO[]后面提供了#{bean.peopleVOList}数组。这个不对。它必须是Collection,最好是ArrayList<PeopleVO>

private List<PeopleVO> peopleVOList;

#{bean.selectedUsers}必须确实是PeopleVO[]。那部分没问题。