Wicket Extensions: DataTable links
Question
I'm using a DataTable (DefaultDataTable) and a DataProvider (SortableDataProvider).
My table has one column like PropertyColumn(new Model("name'), name, name).
Is it possible to have a linkable name instead of a plain name?'''
Answer
The answer is yes
Instead of using a PropertyColumn you have to implement your own column that creates a panel/fragment with the link and text. (Thanks Igor)
Details
There are broadly two variations, the override and the standalone class, but both use the same HTML,
i.e.
<wicket:panel>
<a href="" class="code-quote">"#" wicket:id="link"><span wicket:id="label">link</span></a>
</wicket:panel>
Overriding
columns[0] = new TextFilteredPropertyColumn(new Model("Id"), "id", "id") {
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);
}
A Standalone Component
Posted to the mailing list by Joe Toth (Thanks, Joe)
abstract public class LinkPropertyColumn<T> extends PropertyColumn<T> {
PopupSettings popupSettings;
IModel labelModel;
public LinkPropertyColumn(IModel displayModel, String sortProperty,
String propertyExpression, PopupSettings popupSettings) {
this(displayModel, sortProperty, propertyExpression);
this.popupSettings = popupSettings;
}
public LinkPropertyColumn(IModel displayModel, IModel labelModel) {
super(displayModel, null);
this.labelModel = labelModel;
}
public LinkPropertyColumn(IModel displayModel, String sortProperty,
String propertyExpression) {
super(displayModel, sortProperty, propertyExpression);
}
public LinkPropertyColumn(IModel displayModel, String propertyExpressions) {
super(displayModel, propertyExpressions);
}
@Override
public void populateItem(Item item, String componentId, IModel model) {
item.add(new LinkPanel(item, componentId, model));
}
public abstract void onClick(Item item, String componentId, IModel model);
public class LinkPanel extends Panel {
public LinkPanel(final Item item, final String componentId,
final IModel model) {
super(componentId);
Link link = new Link("link") {
@Override
public void onClick() {
LinkPropertyColumn.this.onClick(item, componentId, model);
}
};
link.setPopupSettings(popupSettings);
add(link);
IModel tmpLabelModel = labelModel;
if (labelModel == null) {
tmpLabelModel = createLabelModel(model);
}
link.add(new Label("label", tmpLabelModel));
}
}
}