Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to create a DataTable with Multiple Row Selection but i'm getting an error here's the link of the tutorial http://www.primefaces.org/showcase/ui/datatableRowSelectionMultiple.jsf :

Here's my xhtml:

    <p:dataTable border="1" value="#{projectAdminisrationMB.projectNoUsersList}"                       var="userObj"                      selection="#            {projectAdminisrationMB.selectedUsers}"  selectionMode="multiple" rowIndexVar="rowIndex"binding="#{table2}"> <p:column id="column3"> <f:facet name="header"> <h:outputText value=" user "></h:outputText> </f:facet>        <h:outputText value="#{userObj.name}"/>                                /   <h:outputText value="#{userObj.lastName}"></h:outputText>    &nbsp;    <h:outputText value="#{userObj.firstName}"></h:outputText>   </p:column>      <f:facet name="footer">        <p:commandButton id="addProjectUser" value=" Add " onclick="dlg1.show()" />         <p:commandButton id="deleteProjectUser" value=" Delete " />        </f:facet>   </p:dataTable> 

Managed Bean :

 @ManagedBean  @SessionScoped  public class ProjectAdminisrationMB implements Serializable {  private static final long serialVersionUID = 1L;  private String projectName; private List <User> projectUsersList; private List<User> projectNoUsersList; private List<User> selectedUsers;  private String projectAdmin;   public ProjectAdminisrationMB() {     super();     AdministrationProjectFinal administrationProjectFinal =new                  AdministrationProjectFinal();     this.projectUsersList=administrationProjectFinal.getUserList();     this.projectNoUsersList=administrationProjectFinal.getNotUserList(); }    public String getProjectName() {     return projectName; }  public void setProjectName(String projectName) {     this.projectName = projectName; }    public List<User> getProjectUsersList() {     return projectUsersList; }    public void setProjectUsersList(List<User> projectUsersList) {     this.projectUsersList = projectUsersList; }    public String getProjectAdmin() {     return projectAdmin; }  public void setProjectAdmin(String projectAdmin) {     this.projectAdmin = projectAdmin; }  public List<User> getProjectNoUsersList() {     return projectNoUsersList; }    public void setProjectNoUsersList(List<User> projectNoUsersList) {     this.projectNoUsersList = projectNoUsersList; }    public List<User> getSelectedUsers() {     return selectedUsers; }    public void setSelectedUsers(List<User> selectedUsers) {     this.selectedUsers = selectedUsers; }      } 

i'm getting this error:

  javax.faces.FacesException: DataModel must implement        org.primefaces.model.SelectableDataModel when selection is enabled..... 
like image 974
Amira Avatar asked Sep 08 '12 19:09

Amira


2 Answers

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}"> 
like image 170
Amira Manai Avatar answered Sep 21 '22 05:09

Amira Manai


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.

like image 30
Nublodeveloper Avatar answered Sep 23 '22 05:09

Nublodeveloper