2015-05-23 56 views
0

我有一個分頁數據表:號碼: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; 
    } 
} 

數據表正確地顯示第列表,但分頁不起作用。這是如何造成的,我該如何解決這個問題?我也嘗試了懶加載,但它也不起作用。

+1

「*我使用Sprimg MVC和PrimeFaces。*」 - 不真實。您不能將它們一起使用(PrimeFaces作爲JSF組件庫)。 – Tiny

+0

對不起,Spring Core -I've已更改 – user3650408

+0

對於延遲加載,您需要爲Project創建lazyDateModel並實現您自己的加載方法...您的示例甚至沒有接近它。 http://www.primefaces.org/showcase/ui/data/datatable/lazy.xhtml – jNick

回答

1

我不確定你的問題出了什麼問題,但是我將你的代碼複製到了一個測試項目中,並且分頁器在PrimeFaces 5.2中工作得很好。

+0

真的,我刪除了bootstrap和bootsfaces依賴關係,分頁工作正在進行中! – user3650408

+0

聽到這真是太棒了!請將其作爲回答張貼並標記爲已接受。將bootstrap包含到問題的標籤中可能會很好,也許其他人將來會遇到同樣的問題。 –

+0

不僅包括bootsfaces作爲標籤,而且在問題本身 – Kukeltje