javax.faces.FacesException: DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled

10,096

Oh sorry, I was so stupid, the problem was id is null. I forgot that I hard coded the values. So anyway for the future people who would encounter the same issue, to make use of the less code row key make sure that you have the following datatable properties set: 1.) rowKey 2.) selection 3.) selectionMode

Also make sure that the rowKey property is not null.

Share:
10,096
czetsuya
Author by

czetsuya

Solution-driven Java EE Software Engineer with over 15 years track record of developing complex enterprise application systems for fintech, billing system, payment gateway, cybersecurity, and e-commerce using Java EE technology stack. Adept at contributing to a highly collaborative work environment and finding technical solutions using Object-Oriented Programming. TECHNICAL SKILLS PROGRAMMING: Spring (Boot, MVC, AOP, Security), Java 8-17, Java EE, Quarkus, JPA, Hibernate, REST, Microservices, OAuth, Functional Programming FRONTEND FRAMEWORKS: JSF, Primefaces, React.js, Angular, HTML5/CSS, Javascript DATA: PostgreSQL, MySQL, MSSQL, Oracle Relational Database, MongoDB, Neo4J, Liquibase, Flyway, Kafka CI/DI: Docker, Docker Compose, Kubernetes, Jenkins PLATFORMS: JBoss / Wildfly, Tomcat, Apache, Ubuntu, CentOS, Cybersecurity AWS: EC2, ECR, ECS, EKS, RDS, Cognito, LightSail, S3, Lambda, Cloudfront, DynamoDB, ElastiCache/Redis, CloudFormation, MSK, OpenSearch SCM: Git, GitHub, GitLab, Maven IDE: IntelliJ, DataGrip, Eclipse, STS TESTING: Junit, SoapUI, Postman

Updated on June 04, 2022

Comments

  • czetsuya
    czetsuya almost 2 years

    I have another case for this issue which is, I have a model that extends a base entity and that base entity has property id. I've use that id as the rowKey and it throws this error. When I set rowKey's value to any property from the model (not the abstract base) the datatable works.

    Note that I'm working on JavaEE6.

    The models:

    @Entity
    @SequenceGenerator(name = "ID_GENERATOR", sequenceName = "USER_ADDRESS_SEQ")
    public class UserAddress extends BaseEntity { //.. }
    
    @MappedSuperclass
    public abstract class BaseEntity implements Serializable, IEntity {
        private static final long serialVersionUID = 1L;
    
        @Id
        @GeneratedValue(generator = "ID_GENERATOR")
        @Column(name = "ID")
        private Long id;
    
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        } ..
    

    The JavaEE6 bean:

    @Stateless
    @Named
    public class UserAddressBean implements Serializable {
        private static final long serialVersionUID = -6104153017102665096L; 
    
        private List<UserAddress> addresses;
        private UserAddress address;
    
        public List<UserAddress> getAddresses() {
            addresses = new ArrayList<UserAddress>();
            UserAddress temp = new UserAddress();
            temp.setDescription("test");
            addresses.add(temp);
    
            temp = new UserAddress();
            temp.setDescription("test");
            addresses.add(temp);
    
            return addresses;
        }
    
        public UserAddress getAddress() {
            return address;
        }
    
        public void setAddress(UserAddress address) {
            this.address = address;
        }..
    

    And the xhtml page:

    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:p="http://primefaces.org/ui"
        template="/shared/page/_oneColumn.xhtml">
        <ui:define name="content">
            <h:form id="form">
                <p:panel>
                    <f:facet name="header"></f:facet>
                    <p:dataTable id="addresses" var="address"
                        value="#{userAddressBean.addresses}" rowKey="#{address.id}"
                        selection="#{userAddressBean.address}" selectionMode="single">
                        <p:column headerText="#{msg['field.description']}">
                            <h:outputText value="#{address.description}" />
                        </p:column>
                    </p:dataTable>
                    <f:facet name="footer"></f:facet>
                </p:panel>
            </h:form>
        </ui:define>
    </ui:composition>
    

    Any idea for the problem?

    Thanks,
    czetsuya