java - Wicket AjaxLink isLinkEnabled() = false renders a clickable span -
i'm using wicket 6.11 , have come across strange error. have wicket ajaxlinks icons inside of them on large application, islinkenabled() can return false based on various circumstances. when does, renders link disabled expect (a span tag em tag inside it), when click on icon, event still fires!
example code:
ajaxlink<object> button = new ajaxlink<object>( "editlocationbutton" ) { private static final long serialversionuid = 1l; public void onclick( ajaxrequesttarget p_target ) { // things } /** * @see org.apache.wicket.markup.html.link.abstractlink#islinkenabled() */ @override protected boolean islinkenabled() { return super.islinkenabled() && getselectedlocation() != null; } };
html file:
<td style="width:0%"> <a href="#" wicket:id="editlocationbutton" class="editbutton iconbutton"> <wicket:message key="button.edit.location"></wicket:message> </a> </td>
rendered html when disabled:
<td style="width:0%"> <span class="editbutton iconbutton" id="editlocationbutton7b6"><em> </em></span> </td>
the editbutton/iconbutton css sets background-image , width/height.
looking in firefox element inspector (not firebug) span has events attached firing ajax call server, why haven't been disabled? bug in wicket? happened upon because tried click on link looked disabled during demo!
any appreciated, thanks.
well seems bug in implementation of ajaxlink. add ajaxeventbehavior following implementation:
protected ajaxeventbehavior newajaxeventbehavior(string event) { return new ajaxeventbehavior(event) { private static final long serialversionuid = 1l; @override protected void onevent(ajaxrequesttarget target) { onclick(target); } @override protected void updateajaxattributes(ajaxrequestattributes attributes) { super.updateajaxattributes(attributes); ajaxlink.this.updateajaxattributes(attributes); } }; }
as can see implementation doesn't care islinkenabled()
method has been overridden. therefore workaround switch isenabled()
1 implicitly deactivate childs of component well. (depending on nature of getselectedlocation()
method advice during onconfigure()
part of component)
Comments
Post a Comment