我有一个分页数据表:
<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;
}
}
数据表正确地显示了列表,但是分页不起作用。这是如何造成的,我该如何解决?我也尝试过延迟加载,但它也不工作
我不知道你这端出了什么问题,但我把你的代码复制到一个测试项目中,paginator在PrimeFaces 5.2中工作得很好。