I have printed a table using the DefaultDataTable object in Apache Wicket.
Now I want to add a link to each table cell.
I found this link which explained some of it, but I have a problem with the first method.
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);
}
What is the transaction and what does the transaction do? What is the LinkPanel class? If there is an easier way, I’ll love to know it!
The “Transaction” is the object in the model of the cell (it is probably coming from the example as it is not coming from wicket). The “LinkPanel” class is an inner class that is also not from wicket. The purpose of this class is to make a panel that will contain a Link. You could add the link directly in the cell without having a panel like LinkPanel
But I would recommend to keep the inner panel (like LinkPanel) approach as I think it is a better practice then adding the link directly. By having your inner panel, you will be able to add label or images to the link very easily, something that would be much more difficult if you add the link directly.
Here is what I usualy do when I need to add links in a table (note that CallDetailRecord is not from wicket, it is just the object I used in this case) :
Hope this help