Last active
December 19, 2015 11:59
-
-
Save wizche/5951514 to your computer and use it in GitHub Desktop.
Simple panel to insert link inside a label. Inject the link on a string with the following link placeholder ${link}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<wicket:panel> | |
<span wicket:id="first"></span> | |
<a wicket:id="link"><span wicket:id="linkLabel"></span></a> | |
<span wicket:id="second"></span> | |
</wicket:panel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment