You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Wicket Extensions: DataTable links

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?'''

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)

There are broadly two variations, the override and the standalone class, but both use the same HTML,
i.e.

<wicket:panel>
<a href="#" wicket:id="link"><span wicket:id="label">link</span></a>
</wicket:panel>
{panel}
        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));
            }
        };
{panel}

... 

{panel}
    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);
        }
{panel}

Posted to the mailing list by Joe Toth (Thanks, Joe)

abstract public class LinkPropertyColumn extends PropertyColumn {

	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));
		}
	}
}
  • No labels