2016-04-29 30 views
1

我在Glassfish服務器4.1上使用Primefaces 5和JDK 1.8。Primefaces 5:使用兩列數據表查看數據

我創建了一個頁面的XHTML結構如下():

<p:dataTable value="#{myBean.myList}" ...> 
    <p:column>MyLabel</p:column> 
    <p:column>MyImage</p:column> 
    <p:column>MyDescription</p:column> 
</p:dataTable> 

所以我在輸出中看到的一個表3列:

label, image and description 
label, image and description 
label, image and description 
label, image and description 
label, image and description 
label, image and description 
... 

對象myList中我的豆返回約50顯示在我的頁面上的行。 如何查看2列上的這些行?如:

label, image and description   label, image and description 
label, image and description   label, image and description 
label, image and description   label, image and description 

謝謝。

+0

如何將數據拆分成兩個列表和顯示2個表? – tak3shi

+0

如果可能的話,我想用一張表... – Diaboliko

+0

以及關於合併MyImage和MyDescription列的問題是什麼? – raven

回答

0

定義它包裝兩個實體中的一個對象的輔助類:

public class DoubleItem{ 

    private String label; 
    private String imageUrl; 
    private String description; 

    private String label2; 
    private String imageUrl2; 
    private String description2; 

    //Getters & setters 

} 

然後在你的託管bean初始化您從當前列表轉換爲一個List<DoubleItem>,這樣你就可以在視圖中遍歷它:

<p:dataTable value="#{myBean.doubleItemList}" var="doubleItem"> 
    <p:column>#{doubleItem.label}</p:column> 
    <p:column>#{doubleItem.imageUrl}</p:column> 
    <p:column>#{doubleItem.description}</p:column> 
    <p:column>#{doubleItem.label2}</p:column> 
    <p:column>#{doubleItem.imageUrl2}</p:column> 
    <p:column>#{doubleItem.description2}</p:column> 
</p:dataTable>