2013-03-02 97 views
1

我正在嘗試使用Wicket顯示錶格。我使用Panel來創建表格,並使用PropertyColumns來添加列。在Wicket中創建表格

如何將幾個列組合爲一個列。

+0

所有我想要做的是有一組列的常見標題。 – sweetcode 2013-03-02 13:51:56

+0

也許嘗試添加您試圖呈現的HTML的最終狀態,因爲它不是很清楚您正在嘗試完成什麼 – ZeusSelerim 2013-03-02 15:49:16

+0

啊!我試圖放置表格的圖像,但我的名譽點阻止了我做這一點。 讓我稍微詳細地解釋什麼,我想。 我的表中有2列,產品和單元測試。 我想除法單元兩個部分,通過和失敗的測試列。 我能創建一個包含兩列的表格我正在生成以下列: 列表 columnList = new ArrayList(); columnList.add(new PropertyColumn (new Model(「Product」),「prod uctName「,」productName「); (新模型(「單元測試」),null,null); – sweetcode 2013-03-02 18:10:04

回答

4

看來您正在使用DataTable或後代。對於你的情況,我會使用一個ListView,你可以更容易地控制輸出HTML。

在HTML:

<table> 
    <thead> 
    <tr> 
     <th rowspan="2">Product</th> 
     <th colspan="2">Unit tests</th> 
    </tr> 
    <tr> 
     <th>Passed</th> 
     <th>Failed</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr wicket:id="listView"> 
     <td wicket:id="productComponent">Product</td> 
     <td wicket:id="passedComponent">PassedColumn</td> 
     <td wicket:id="failedComponent">FailedColumn</td> 
    </tr> 
    </tbody> 

在Java:

add(new ListView<SomeDetails>("listView", listData) 
{ 
     public void populateItem(final ListItem<SomeDetails> item) 
     { 
       final SomeDetails data= item.getModelObject(); 
       item.add(new Label("productComponent", data.getProduct())); 
       item.add(new Label("passedComponent", data.getPassed())); 
       item.add(new Label("failedComponent", !data.getPassed())); 
     } 
}); 
+1

我認爲您的檢票ID應該位於tr元素上,而不是tbody元素 – 2014-02-28 22:58:33

+0

Pappin如果id位於tbody標籤上,則每個SomeDetails項目都會重複。 – Kiril 2014-03-05 18:22:04