p:dataTable不会对

时间:2015-05-23 12:23:31

标签: jsf primefaces datatable pagination

我有一个分页数据表:

<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>

基于此实体:

@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.
}

并填充在这个bean中(为简洁起见,我省略了DAO / Service部分,我在@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;
    }
}

数据表正确显示列表,但分页不起作用。这是怎么造成的,我该如何解决?我也试过延迟加载,但它也不起作用。

1 个答案:

答案 0 :(得分:1)

我不确定到底出了什么问题,但是我将你的代码复制到了一个测试项目中,并且这个paginator与PrimeFaces 5.2一起工作得很好。