我已經使用Apache Wicket中的DefaultDataTable對象打印了一個表。
現在我想添加一個鏈接到每個表格單元格。添加到wicket中的表的鏈接
我發現this link其中解釋了一些,但我有第一種方法的問題。
columns[0] = new TextFilteredPropertyColumn(new Model("Id"), "id", "id") {
// add the LinkPanel to the cell item
public void populateItem(Item cellItem, String componentId, IModel model) {
final Transaction transaction = (Transaction) model.getObject(cellItem);
cellItem.add(new TransactionList.LinkPanel(componentId, transaction));
}
};
private class LinkPanel extends Panel {
public LinkPanel(String id, Transaction transaction) {
super(id);
final String name = transaction.getId();
PageParameters param = new PageParameters("id=" + name);
BookmarkablePageLink link = new BookmarkablePageLink("link", TransactionDetail.class, param);
link.add(new Label("label", name));
add(link);
}
什麼是交易以及交易是做什麼的?什麼是LinkPanel類?如果有更簡單的方法,我很樂意知道它!
這不會失敗,因爲沒有標記與檢票:身份證「ID」,沒有在你的單元格的標記HREF標記? – Nicktar 2012-08-14 14:23:41
我寫的代碼確實有錯誤。我編輯了我的答案,以便代碼正常工作(我在AjaxFallbackDefaultDataTable中測試了它,它正在工作)。但是,正如我在答覆中所說的那樣,我不建議這樣做,因爲您將標記添加到鏈接時遇到問題。 @Nicktar感謝您指出:) – jrochette 2012-08-14 14:44:29
如果我嘗試它,它會工作,但在表中的單元格中,它顯示'[cell]'字符串,而不是模型的值。我怎麼能得到模型的值而不是'[cell]',就像我添加新的'Link'項目一樣? – victorio 2013-12-06 12:52:53