2013-12-23 24 views
2

我想添加到我所有的樹節點編輯和創建新的子鏈接,但我得到錯誤,與id單元格的孩子已經存在。Wicket在同一列中的兩個鏈接

columns.add(new AbstractColumn<Classification, String>(Model.of("")) { 
     private static final long serialVersionUID = 1L; 

     @Override 
     public void populateItem(Item<ICellPopulator<Classification>> cellItem, String componentId, 
       final IModel<Classification> rowModel) { 

      cellItem.add(new TreeLinkPanel(componentId, rowModel, tree)); 
     } 
    }); 
    columns.add(new AbstractColumn<Classification, String>(Model.of("")) { 
     private static final long serialVersionUID = 1L; 

     @Override 
     public void populateItem(Item<ICellPopulator<Classification>> cellItem, String componentId, 
       final IModel<Classification> rowModel) { 

      cellItem.add(new ClassificationNewLink(componentId, rowModel, tree)); 
     } 
    }); 

現在我正在這樣做,但這個是醜陋的。我無法爲我的專欄撰寫標題。任何想法如何將兩個鏈接放在同一列?

回答

4

電池項目僅僅是一個擁有它的檢票ID的組成部分,所以你不能真正增加更比一次。

最簡單的方法是創建一個包含任何要添加的組件的面板或片段(例如兩個鏈接)。

您的代碼示例:

columns.add(new AbstractColumn<Classification, String>(Model.of("")) { 
    private static final long serialVersionUID = 1L; 

    @Override 
    public void populateItem(Item<ICellPopulator<Classification>> cellItem, String componentId, final IModel<Classification> rowModel) { 
     // your model 
     cellItem.add(new MyCellPanel(componentId, rowModel, tree)); 
    } 
}); 

MyCellPanel類的例子:

public class MyCellPanel extends Panel { 

    MyCellPanel(String componentId, final IModel<Classification>rowModel, final Tree tree) { 
     super(componentId, rowModel); 
     add(new TreeLinkPanel("treeLink", rowModel, tree); { 
     add(new ClassificationNewLink("classificationNewLink", rowModel, tree); { 

    } 

} 

MyCellPanel.html例如:

<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<body> 
    <wicket:panel xmlns:wicket="http://wicket.apache.org"> 
     <div wicket:id="treeLink">tree link</div> 
     <a wicket:id="classificationNewLink">classification link</a> 
    </wicket:panel> 
</body> 
0

這只是胡亂猜測,但如果你嘗試填充柱只有一次:

columns.add(new AbstractColumn<Classification, String>(Model.of("")) { 
    private static final long serialVersionUID = 1L; 

    @Override 
    public void populateItem(Item<ICellPopulator<Classification>> cellItem, String componentId,final IModel<Classification> rowModel) { 
     // your model 
     cellItem.add(new TreeLinkPanel("treeLinkPanelId", rowModel, tree)); 
     // the add link 
     cellItem.add(new ClassificationNewLink("classificationNewLinkId", rowModel, tree)); 
    } 
}); 
+1

如果我下站在你的代碼示例中,它將引發WicketRuntimeException,因爲您在同一級別的組件層次結構中添加了具有相同componentId的兩個組件,不是嗎? –

+0

是的,你是對的。我錯過了。 – polypiel

相關問題