Well the code is a bit more complex that what I originally pasted.
ComponentA is instantiated in an overridable method so that subclasses can
provide a different implementation. Furthermore, the model cannot be
decided at initialization time, so you can't simply call
componentA.setModel() right after it is constructed. So I thought about
using a behavior which can be added after the component is constructed and
which can change the model whenever needed.

Nonetheless, based on  your feedback, I think I have found a way to
refactor it such that the model is provided at initialization time.

But I guess the question still stands - can Behavior#onConfigure change a
component's model or is this not a valid operation?

On Wed, Apr 8, 2015 at 12:13 PM, Patrick Davids <
patrick.dav...@nubologic.com> wrote:

> Hi,
> quite unusal to me using a behavior to set a model.
>
> Why dont you delegate to your inner textfiled by implementing an own
> setXYZModel()-method?
>
> Or bind your inner textfield direct by providing a particular model in
> your Constructor of your custom MyFormComponentPanel?
> And no onInitialize()-method...
>
> public class MyFormComponentPanel extends FormComponentPanel {
>   public MyFormComponentPanel(IModel myModel){
>     add(new TextField("id", myModel));
>   }
> }
> (add generics if needed)
>
>
> Patrick
>
>
> Am 08.04.2015 um 09:27 schrieb mscoon:
>
>> Hi all,
>>
>> I have a FormComponentPanel. Is it okay if I set its components models
>> using a behavior that overrides onConfigure() as below?
>>
>> public class MyFormComponentPanel extends FormComponentPanel {
>>
>>      protected void onInitialize() {
>> super.onInitialize();
>>                  componentA = new TextField...
>>                  componentA.add(new Behavior() {
>>                           @Override
>> public void onConfigure(Component component) {
>>                                   componentA.setModel(...);
>>                           }
>>                  });
>> }
>>
>> thanks
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to