See https://github.com/l0rdn1kk0n/wicket-bootstrap/tree/master/library/src/main/java/de/agilecoders/wicket/markup/html/bootstrap/behavior
There are few CssClassName* classes which are a bit more sophisticated than Wicket's AttributeModifier. On Thu, Sep 27, 2012 at 12:28 PM, Martijn Dashorst <martijn.dasho...@gmail.com> wrote: > I encounter the following code quite often in our company's codebase: > > @Override > protected void onBeforeRender() { > add(AttributeModifier.replace("class", someCondition ? "someValue" > : "someOtherValue")); > } > > This is of course a (often a minor) memory leak: each time the > component gets rendered, a new attribute modifier is added to the list > of behaviors, each overwriting the class attribute. The correct code > would of course be: > > @Override > protected void onInitialize() { > add(AttributeModifier.replace("class", new > AbstractReadOnlyModel<String>() { > public String getObject() { > return someCondition ? "someValue" : "someOtherValue"; > } > })); > } > > Another solution would be to make the attribute modifiers temporary. > Problem with that is silent failures of attributemodifiers added in > onInitialize and constructors or guarded by hasBeenRendered(). > > My main question is: do you encounter this kind of attribute > modification in your application code? Were you aware of this problem? > > Martijn > > PS. I guess it is time to write some blog articles about this... -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com