user3650408
user3650408

Reputation: 139

p:dataTable does not paginate

I have a paginated data table:

<h:form>
    <p:dataTable var="proj" value="#{orderListView.projects}"
                 paginator="true" rows="3"
                 paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
    >
        <p:column sortBy="#{proj.id}">
            <h:outputText value="#{proj.id}" />
        </p:column>
        <p:column  sortBy="#{proj.name}">
            <h:outputText value="#{proj.name}" />
        </p:column>
        <p:column sortBy="#{proj.displayName}">
            <h:outputText value="#{proj.displayName}" />
        </p:column>
    </p:dataTable>
</h:form>

Which is based on this entity:

@Entity
public class Project implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    private String displayName;
    private String name;

    public Project() {}

    public Project(int id, String displayName, String name) {
        this.id = id; 
        this.displayName = displayName;
        this.name = name;
    }

    // Getters+setters.
}

And is populated in this bean (for brevity, I have omitted the DAO/Service part and I am hardcoding the model in @PostConstruct):

@ManagedBean
@RequestScoped
public class OrderListView {

    private List<Project> projects;

    @PostConstruct
    public void init() {
        projects = new ArrayList<Project>();
        projects.add(new Project(10, "Cruze", "cruze"));
        projects.add(new Project(11, "Dark-Hive", "dark-hive"));
        projects.add(new Project(12, "Delta", "delta"));
        projects.add(new Project(10, "Cruze", "cruze"));
        projects.add(new Project(11, "Dark-Hive", "dark-hive"));
        projects.add(new Project(12, "Delta", "delta"));
        projects.add(new Project(13, "Dot-Luv", "dot-luv"));
        projects.add(new Project(14, "Eggplant", "eggplant"));
        projects.add(new Project(15, "Excite-Bike", "excite-bike"));
        projects.add(new Project(16, "Flick", "flick"));
        projects.add(new Project(17, "Glass-X", "glass-x"));
        projects.add(new Project(18, "Cruze", "cruze"));
        projects.add(new Project(19, "Dark-Hive", "dark-hive"));
        projects.add(new Project(20, "Delta", "delta"));
        projects.add(new Project(23, "Dot-Luv", "dot-luv"));
        projects.add(new Project(24, "Eggplant", "eggplant"));
        projects.add(new Project(25, "Excite-Bike", "excite-bike"));
        projects.add(new Project(26, "Flick", "flick"));
        projects.add(new Project(27, "Glass-X", "glass-x"));
    }

    public List<Project> getProjects() {
        return projects;
    }
}

The data table correctly shows the list, but pagination doesn't work. How is this caused and how can I solve it? I also tried lazy loading, but it also doesn't work.

Upvotes: 0

Views: 670

Answers (1)

Raphael H
Raphael H

Reputation: 69

I'm not sure what went wrong on your end, but I copied your code into a testproject and the paginator works just fine with PrimeFaces 5.2.

Upvotes: 1

Related Questions