Everyone,

As discussed separately on this list and now included in WICKET-5640 <https://issues.apache.org/jira/browse/WICKET-5640>, I prefer Wicket not to modify my HTML using its assumptions of how I want to handle e.g. how a component should look when it is disabled. It turns out that WICKET-4904 <https://issues.apache.org/jira/browse/WICKET-4904> has already turned off automatic generation of <em><span> wrapping of disabled links for Wicket 7.x, which is a great start.

The Yahoo! Pure CSS library, as one example, requires that I use the pure-button-disabled CSS class for my disabled links. I in no way desire to include knowledge of third-party libraries in the Wicket framework itself, but I want to make Wicket easy to support them. So I have created a simple DisabledClassAttributeAppender class. Using the Yahoo! Pure CSS as an example, here is all I have to do for my links:

    myLink.add(new DisabledClassAttributeAppender("pure-button-disabled"));

It works like a dream! I will contribute this class, and hope it gets included in an upcoming Wicket version.

But the question remains of how I indicate this for all my links. I don't want to manually add a DisabledClassAttributeAppender to each link I create. Moreover, I do /not/ think it appropriate to subclass all my links (e.g. YahooPureBookmarkablePageLink); that would put too much knowledge of my CSS framework into my code base, tightly coupling my styling to my code. (ugh)

I propose the creation of a class named BehaviorBundle. It would implement IComponentInstantiationListener, and allow essentially a mapping between component types and behaviors. When a component is instantiated, the BehaviorBundle would check the type (appropriately recognizing subclasses) and add the specified behaviors. Here is an example of how it would work in MyApplication.onInit():

    BehaviorBundle yahooPureCSSBehaviorBundle=new BehaviorBundle();
behaviorBundle.addBehavior(AbstractLink.class, new DisabledClassAttributeAppender("pure-button-disabled"));
    //other behaviors for the Yahoo! Pure CSS library
getComponentInitializationListeners().add(yahooPureCSSBehaviorBundle);

That's all! Suddenly all my links would Do The Right Thing for the Yahoo! Pure CSS library. If I later switched to another library such as Bootstrap, I would simply switch to another BehaviorBundle and be done with it! Plus it's more declarative than the old getMarkupSettings().setDefaultBeforeDisabledLink(...), which had me embedding HTML in the code, and which was specific to certain elements.

The approach I am proposing allows one to encapsulate a whole series of behaviors and component associations within one "bundle". Future versions of Wicket (or third parties) could even offer per-framework modules, so that developers wouldn't have to roll their own. The BehaviorBundle class itself would be extremely simple, as the IComponentInstantiationListener is already in place. This solution I believe is in the spirit of the Wicket architecture, yet brings capabilities that Wicket doesn't currently support (to my knowledge).

Any thoughts? I'm going to write this class for our current project anyway, and I'd be happy if everyone likes the idea, so that I could contribute it for Wicket 7.x.

Cheers,

Garret

Reply via email to