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

just add this attribute rowKey to the datatable tag :

<p:dataTable border="1" value="#{projectAdminisrationMB.projectNoUsersList}" 
 var="userObj"
 rowKey="#{userObj.name}"selection="#{projectAdminisrationMB.selectedUsers}"
 selectionMode="multiple" rowIndexVar="rowIndex"
 binding="#{table2}">

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


Alternatively to rowKey you can wrap your data in a custom model which really implements org.primefaces.model.SelectableDataModel. This is helpful if

  • all of your your classes have the same kind of @Id (e.g. a long) and can implement the same interface (e.g. EjbWithId)
  • you want to add additional functionalities to your data which are not domain specific and don't belong e.g. User.

The interface may be something like this:

public interface EjbWithId
{
  public long getId();
  public void setId(long id);
}

Then a generic implementation of SelectableDataModel for all your classes can be used:

public class PrimefacesEjbIdDataModel <T extends EjbWithId>
       extends ListDataModel<T> implements SelectableDataModel<T>
{    
  public PrimefacesEjbIdDataModel(List<T> data)
  {  
    super(data);
  }  

  @Override public T getRowData(String rowKey)
  {  
    List<T> list = (List<T>) getWrappedData();  

    for(T ejb : list)
    {  
      if(ejb.getId()==(new Integer(rowKey))){return ejb;}  
    }
    return null;  
  }  

  @Override public Object getRowKey(T item) {return item.getId();}
}

In your @ManagedBean:

private PrimefacesEjbIdDataModel<User> dmUser; //+getter
dmUser = new PrimefacesEjbIdDataModel<User>(administrationProjectFinal.getUserList());