5

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?

Community
  • 1
  • 1
Amira
  • 3,184
  • 13
  • 60
  • 95

2 Answers2

9

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • The group name is never null , but i tried the id and the error persist. should my managedBean implement SelectableDataModel ? – Amira Nov 12 '12 at 11:11
  • 1
    No, not your managed bean. The data model, exactly as the exception message says. The property behind ``. Coming back to the concrete problem: well, sorry, exceptions don't lie. If you're using `rowKey` this way, then the only cause for this exception is that at least one of the items has a `null` group name. Perhaps the data loading logic is broken? Try to boil down a concrete SSCCE example demonstrating the problem. – BalusC Nov 12 '12 at 11:17
-1

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.

  • 1
    This sounds like a potentially useful comment to the question, but maybe not a definitive "answer" as such. – Jake Jan 03 '17 at 19:53