Skip to content

Instantly share code, notes, and snippets.

@wizche
Last active December 19, 2015 11:59

Revisions

  1. wizche renamed this gist Jul 8, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. wizche created this gist Jul 8, 2013.
    10 changes: 10 additions & 0 deletions Example.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    LinkLabel myLabel = new LinkLabel("description",
    "First ${link} second", "my link", new ILinkListener() {

    private static final long serialVersionUID = 1L;

    @Override
    public void onLinkClicked() {
    // Your desired onClick action
    }
    });
    5 changes: 5 additions & 0 deletions LinkLabel.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    <wicket:panel>
    <span wicket:id="first"></span>
    <a wicket:id="link"><span wicket:id="linkLabel"></span></a>
    <span wicket:id="second"></span>
    </wicket:panel>
    44 changes: 44 additions & 0 deletions LinkLabel.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    public class LinkLabel extends Panel {

    private static final long serialVersionUID = 1L;

    public LinkLabel(String id, String model, String linkName,
    ILinkListener linkListener) {
    super(id);
    setRenderBodyOnly(true);
    String[] split = model.split("\\$\\{link\\}");
    if (split.length == 2) {
    Label first = new Label("first", split[0]);
    Label second = new Label("second", split[1]);

    add(first);
    add(second);
    add(generateLink(linkListener, linkName));
    } else if (split.length == 1) {
    Label first = new Label("first", split[0]);
    Label second = new Label("second");
    second.setVisible(false);
    add(first);
    add(second);
    add(generateLink(linkListener, linkName));
    } else {
    throw new UnsupportedOperationException(
    "LinkLabel needs the ${link} placeholder!");
    }
    }

    private Link<?> generateLink(final ILinkListener linkListener,
    String linkName) {
    Label linkLabel = new Label("linkLabel", linkName);
    Link<String> link = new Link<String>("link") {
    private static final long serialVersionUID = 1L;

    @Override
    public void onClick() {
    linkListener.onLinkClicked();
    }
    };
    link.add(linkLabel);
    return link;
    }
    }