Last active
December 18, 2015 18:29
-
-
Save MartinKnopf/5826123 to your computer and use it in GitHub Desktop.
Wicket ExternalLink with Model<DTO>
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
package org.horsed.gists.externallink; | |
import org.apache.wicket.markup.ComponentTag; | |
import org.apache.wicket.markup.html.WebMarkupContainer; | |
import org.apache.wicket.markup.html.panel.Panel; | |
import org.apache.wicket.model.IModel; | |
/** | |
* Imitation of an {@link org.apache.wicket.markup.html.link.ExternalLink} that provides the {@code href} attribute | |
* through a callback. | |
* <p/> | |
* <strong>Note: </strong>This is actually just a {@link WebMarkupContainer} and therefore puts the {@code href} | |
* attribute on any HTML tag (even it is not an anchor tag). | |
* | |
* @author Martin Knopf | |
* | |
*/ | |
public abstract class ExternalLink extends Panel { | |
public ExternalLink(String id) { | |
super(id); | |
} | |
public ExternalLink(String id, IModel<?> model) { | |
super(id, model); | |
} | |
@Override | |
protected void onComponentTag(ComponentTag tag) { | |
super.onComponentTag(tag); | |
tag.put("href", getHref()); | |
} | |
/** | |
* Returns the value of the {@code href} attribute of this {@link Component}. | |
* | |
* @return | |
*/ | |
protected abstract String getHref(); | |
} |
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
package org.horsed.gists.externallink; | |
import org.apache.wicket.markup.html.basic.Label; | |
import org.apache.wicket.model.IModel; | |
public class LogoLink extends ExternalLink { | |
private final IModel<String> model; | |
public LogoLink(String id, IModel<String> model) { | |
super(id, model); | |
this.model = model; | |
} | |
@Override | |
protected void onInitialize() { | |
super.onInitialize(); | |
add(new Label("text", model.getObject())); | |
} | |
@Override | |
protected String getHref() { | |
return "google.de"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment