ERROR: DataModel must implement ... SelectableDataModel

UI Components for JSF
Post Reply
User avatar
jim@jimtough.com
Posts: 142
Joined: 03 Jun 2011, 18:06
Location: Canada

01 Sep 2011, 14:45

I've just updated my project code to use the 3.0-M3 (final) release. My last snapshot version was still using the PrimeDataModel class for <p:dataTable> that had single selection enabled. When I updated to 3.0-M3 final that class no longer existed. I looked at the current 3.0 Showcase and the code samples shown on the page don't show any data model references at all. This is the way single selection used to work. So I reverted back to my old code that did not use the (now defunct) PrimeDataModel and looks like the code samples in the 3.0 Showcase.

So why am I getting this exception?
DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled.
Is the 3.0 Showcase code stale or have I made a mistake?
PF 3.0,
Mojarra 2.1.4,
Tomcat 7.0.14,
Eclipse Indigo,
IE 7, Chrome

Image
http://stackoverflow.com/users/346112/jim-tough

Would rather be a Decepticon...

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

01 Sep 2011, 16:21

Cagatay changed the selection handling and introduced the rowkey. If you have a list with objects, you can just use rowKey="#{object.id}"
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

User avatar
undermensch
Posts: 140
Joined: 08 Jul 2010, 14:37
Location: Florida, United States

01 Sep 2011, 16:26

If you enable selection, you need to define rowKey attribute for the datatable or point value to a data model like my example below....

Code: Select all

public class StudentDataModel extends ListDataModel<Student> implements SelectableDataModel<Student>{

    public StudentDataModel(List<Student> list) {
        super(list);
    }    

    @Override
    public Student getRowData(String rowKey) {
        List<Student> students = (List<Student>)this.getWrappedData();
        for(Student student : students){
            if(student.getIdStudent().toString().equalsIgnoreCase(rowKey)){
                return student;
            }
        }
        return null;
    }

    @Override
    public Object getRowKey(Student object) {
        return object.getIdStudent();
    }
PrimeFaces-11.0.6 / Wildfly 24

User avatar
jim@jimtough.com
Posts: 142
Joined: 03 Jun 2011, 18:06
Location: Canada

01 Sep 2011, 16:28

@undermensch

Thanks, that works. I was implementing SelectableDataModel<XYZ> but not extending ListDataModel<XYZ>.
PF 3.0,
Mojarra 2.1.4,
Tomcat 7.0.14,
Eclipse Indigo,
IE 7, Chrome

Image
http://stackoverflow.com/users/346112/jim-tough

Would rather be a Decepticon...

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 28 guests