You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Mattijs Hoitink <ma...@func.nl> on 2007/10/26 11:46:34 UTC
automatically add behavior to form components
hi there,
I have written a behavior to change the appearance of a form component
when it's invalid.
I'm now looking for a way to automatically add this behavior to all
components in a form.
I already played around with visitFormComponents like this:
visitFormComponents(new FormComponent.AbstractVisitor() {
@Override
protected void onFormComponent(FormComponent formComponent) {
if(!(formComponent instanceof Button)) {
formComponent.add(new ValidationStyleBehavior());
}
}
});
The code above is working like it's supposed to. But if I use it in this
way, I have to repeat this piece of code in the constructor of all the
forms in my application.
My question is: What would be the best way to have a Form execute this
code? With another behavior on the form, that visits the form components
and adds the second behavior? Or by implementing an interface? Or am I
stuck with repeating the code for every form?
--
Mattijs Hoitink
Func. Internet Integration
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: automatically add behavior to form components
Posted by Johan Compagner <jc...@gmail.com>.
you could look at;
IComponentOnBeforeRenderListener
On 10/26/07, Mattijs Hoitink <ma...@func.nl> wrote:
>
> hi there,
>
> I have written a behavior to change the appearance of a form component
> when it's invalid.
> I'm now looking for a way to automatically add this behavior to all
> components in a form.
>
> I already played around with visitFormComponents like this:
> visitFormComponents(new FormComponent.AbstractVisitor() {
> @Override
> protected void onFormComponent(FormComponent formComponent) {
> if(!(formComponent instanceof Button)) {
> formComponent.add(new ValidationStyleBehavior());
> }
> }
> });
>
> The code above is working like it's supposed to. But if I use it in this
> way, I have to repeat this piece of code in the constructor of all the
> forms in my application.
>
> My question is: What would be the best way to have a Form execute this
> code? With another behavior on the form, that visits the form components
> and adds the second behavior? Or by implementing an interface? Or am I
> stuck with repeating the code for every form?
>
> --
> Mattijs Hoitink
> Func. Internet Integration
> W http://www.func.nl
> T +31 20 4230000 <LiveCall:+31204230000>
> F +31 20 4223500 <LiveCall:+31204223500>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>