Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled

Tags:

jsf

primefaces

I was trying to implement one DataTable Editable with RowSelection enabled.

But it is throwing out an exception:

DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled.

I implemented the DataModel in both the object class and the managed bean class but the error is the same. Now only a blank table appears for me. Please help.

like image 786
user1281029 Avatar asked May 09 '12 10:05

user1281029


4 Answers

There are two solutions for this problem:

  1. Adding rowKey, selection and selectionMode attributes to dataTable
  2. Implementing SelectableDataModel interface and extending a DataModel like ListDataModel for filling the dataTable

First one is Simpler. Adding rowKey="#{myEntity.carID}" to your p:dataTable should solve your problem

like image 130
rags Avatar answered Nov 13 '22 19:11

rags


You can get this error if you try to add a new item to the underlying list and forget to assign a value to the new item's rowKey (the rowKey is null).

like image 33
Nublodeveloper Avatar answered Nov 13 '22 18:11

Nublodeveloper


In addition to the Solutions given by rags, I would like to mention that if the row key is "NULL" or if your entire List is "NULL" you may get the same error, even if you have completed all the above mentioned steps. If you want to show 0 row, return a list with 0 items. Don't return null for the list.

like image 3
RajdeepS Avatar answered Nov 13 '22 18:11

RajdeepS


The error message indicates that your DataModel does not implement the SelectableDataModel interfaces. It needs to be a separate class. This is an example from the PF showcase how the data table definition needs to be done:

import org.primefaces.model.SelectableDataModel;  

public class CarDataModel extends ListDataModel<Car> implements SelectableDataModel<Car> {    
   ...
}
like image 2
Matt Handy Avatar answered Nov 13 '22 20:11

Matt Handy