我有一個分頁數據表:號碼:dataTable的不分頁
<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 /服務部,我硬編碼在@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;
}
}
數據表正確地顯示第列表,但分頁不起作用。這是如何造成的,我該如何解決這個問題?我也嘗試了懶加載,但它也不起作用。
「*我使用Sprimg MVC和PrimeFaces。*」 - 不真實。您不能將它們一起使用(PrimeFaces作爲JSF組件庫)。 – Tiny
對不起,Spring Core -I've已更改 – user3650408
對於延遲加載,您需要爲Project創建lazyDateModel並實現您自己的加載方法...您的示例甚至沒有接近它。 http://www.primefaces.org/showcase/ui/data/datatable/lazy.xhtml – jNick