if I have an input wrapped in a div (together with other stuff),
how can I pass to that input whatever beavior is added to the wrapper?
Example:
Component HTML goes like <div> <img> <input> ...
Then I’d like to add it like add( new MyComponent("foo", model).add( new AjaxEventBehavior("onupdate"){ ... } (but that doesn’t work since only FormComponent can receive (AjaxEventBehavior`s).
I assume I could move this behavior object from wrapper to input, but don’t know where – is there some “after construction” listener?
Or should I do it completely different, like passing the behavior as a parameter?
The reason to keep it like above is to make it transparent for the user of the component.
You could override the
MarkupContainer#add(Behavior... behaviors)method of the wrapping component. This would of course mean that the wrapping component could never receive any behaviors:One option is to separate the wrapping component to be a
Border, which can be used to surround components with content. This would, however, reduce the “transparency” of the wrapping element. (See the example on the Javadoc page).Then use it like this:
With this kind of markup
The
Borderapproach would enable you to reuse the border component without the `TextField? component. E.g., if you want to add a drop-down: