Hi,I decided to wrote a behavior to do what I want. Just in case anybody is interested, I will attach it to this email. You can use it like so:
ExternalLink externalLink = new ExternalLink("externalLink", "http://www.google.com");
externalLink.add(new DisableLinkBehavior()); externalLink.setEnabled(enabled); add(externalLink);The output is exactly the same as with Link. You can also specify "beforeDisabledLink" and "afterDisabledLink" strings in the constructor of DisableLinkBehavior if you don't like the default <i> </i>.
Regards, Sebastiaan Sebastiaan van Erk wrote:
Hi,It indeed looks more like an omission than a bug. I'll make a feature request out of it. :-)Regards, Sebastiaan Jonathan Locke wrote:yeah, more like an omission, but this is definitely a problem so far as i recall. Kent Tong wrote:Sebastiaan van Erk wrote:Ok, to answer my own question, it seems that ExternalLink does not have the ability to be disabled like Link.Looks like a bug to me. I'd suggest that you submit a JIRA issue at http://issues.apache.org/jira/browse/WICKET
package com.sebster.util.wicket; import org.apache.wicket.Component; import org.apache.wicket.behavior.IBehavior; import org.apache.wicket.markup.ComponentTag; @SuppressWarnings("nls") public class LinkDisableBehavior implements IBehavior { private static final long serialVersionUID = 1L; private final String beforeDisabledLink; private final String afterDisabledLink; public LinkDisableBehavior() { this("<i>", "</i>"); } public LinkDisableBehavior(final String beforeDisabledLink, final String afterDisabledLink) { this.beforeDisabledLink = beforeDisabledLink; this.afterDisabledLink = afterDisabledLink; } public String getBeforeDisabledLink() { return beforeDisabledLink; } public String getAfterDisabledLink() { return afterDisabledLink; } public void afterRender(final Component component) { if (!isLinkEnabled(component) && getAfterDisabledLink() != null) { component.getResponse().write(getAfterDisabledLink()); } } public void beforeRender(final Component component) { if (!isLinkEnabled(component) && getBeforeDisabledLink() != null) { component.getResponse().write(getBeforeDisabledLink()); } } public void bind(final Component component) { // Do nothing. } public void detach(final Component component) { // Do nothing. } public void exception(final Component component, final RuntimeException exception) { // Do nothing. } public boolean getStatelessHint(final Component component) { return true; } public boolean isEnabled(final Component component) { return true; } public boolean isTemporary() { return false; } public void onComponentTag(final Component component, final ComponentTag tag) { if (!isLinkEnabled(component)) { // if the tag is an anchor proper if (tag.getName().equalsIgnoreCase("a") || tag.getName().equalsIgnoreCase("link") || tag.getName().equalsIgnoreCase("area")) { // Change anchor link to span tag tag.setName("span"); // Remove any href from the old link tag.remove("href"); tag.remove("onclick"); } // if the tag is a button or input else if ("button".equalsIgnoreCase(tag.getName()) || "input".equalsIgnoreCase(tag.getName())) { tag.put("disabled", "disabled"); } } } protected boolean isLinkEnabled(final Component component) { return component.isEnabled() && component.isEnableAllowed(); } }
smime.p7s
Description: S/MIME Cryptographic Signature