Hi,

You are using Behavior in a strange way.
component.add(behavior) will call behavior#onBind(component) because Wicket
knows that the behavior is used by this component.
Later when Wicket starts to render the components it calls the Behavior's
methods like: beforeRender(), afterRender(), etc.
What's strange in your approach is that a behavior is added to one
component (the page?!) that is completely unrelated to the main task and it
holds references to some other components which should be manipulated
somehow ...
Better mark these components somehow (annotation, marker interface, base
class, ...) and use IComponentInstantiationListener to add the
AttributeModifier to all such components.

 Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov


On Mon, Jul 21, 2014 at 2:45 PM, Entropy <[email protected]> wrote:

> > Instead of doing:
> >   page.add(new MyBehavior(components))
> > do
> >  Behavior b = AttributeModifier.append(....);
> >  for (Component c : components) {
> >     c.add(b)
> >  }
>
> Certainly that would work,  I am trying to create a re-usable Behavior for
> my app that any page wishing to incorporate this feature can add.  I
> thought
> behaviors would be perfect for this, but it seems one event is to early
> (the
> components may not have been all added yet) and another too late (not
> allowed to add AttributeModifiers).
>
> I have a common abstract page class from which all my classes extend, and I
> certainly could put a method on there, but I'd be relying on the individual
> programmer to call the method last in his constructor, rather than relying
> on an event which guarantees it.
>
> Seems like there ought to be a goldilocks place to put this...not too
> early,
> not too late.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Behavior-to-modify-attributes-tp4666687p4666714.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to