DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled, but I have already defined rowKey

淺唱寂寞╮ 提交于 2019-11-30 05:27:53

问题


I've a selectable PrimeFaces 3.4.1 datatable:

<p:dataTable value="#{projectAdminisrationMB.selectedUserMemberOfGroups}" var="group1" 
    rowKey="#{group1.name}" selectionMode="single" selection="#{projectAdminisrationMB.selectedBelongToGroup}">
    ...
</p:dataTable>

I'm getting this error:

com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback visit Grave: javax.faces.FacesException: DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled.

But I have already set rowKey as per FacesException: DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled. How is this caused and how can I solve it?


回答1:


This can occur when the EL expression in the rowKey attribute ever evaluates null.

Make sure that the name property of your Group instance is never null. Otherwise better use a property representing the autogenerated DB primary key, such as #{group1.id} — if you have one.




回答2:


Just FYI - I have experienced the same error when using the Primefaces column filters. If I use the filters and click on a refresh button to reload the table, I then experience the error. If I don't use the column filters, then the error never occurs when I refresh the table. I have a couple of column filters that perform filter logic on the same field that contains the full name by extracting either the first name or last name, so I suspect this issue is in relation to those filters. I haven't figured out the issue yet but I wanted to share this with you in case that it helps. And I am using rowKey.



来源:https://stackoverflow.com/questions/13342524/datamodel-must-implement-org-primefaces-model-selectabledatamodel-when-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!