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

后端 未结 6 1324
说谎
说谎 2020-12-06 09:26

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

But it is throwing out an exception:

DataModel must implement org.

相关标签:
6条回答
  • 2020-12-06 09:56

    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

    0 讨论(0)
  • 2020-12-06 09:56

    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.

    0 讨论(0)
  • 2020-12-06 10:05

    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> {    
       ...
    }
    
    0 讨论(0)
  • 2020-12-06 10:07

    Possibly the error is because the row.id is empty or null in my case the solution be change this:

    rowKey="row.id" 
    

    to this:

    rowKey="row" 
    

    And the Object of datatable, for example

    List<Row> collectionOfDataTable = new ArrayList<>();
    

    Row (Object) implements Serializable:

    public class Row implements Serializable{...}
    
    0 讨论(0)
  • Don't forget to surround the rowKey value within EL syntax.

    rowKey="row.id" 
    

    will fail but

    rowKey="#{row.id}" 
    

    will succeed.

    0 讨论(0)
  • 2020-12-06 10:09

    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).

    0 讨论(0)
提交回复
热议问题