extracting model [objects] in constructors of components.
Best practices says: DONT

How about creating the address lazily?

IModel<Address> address = new CreateAndSetIfNull(new PropertyModel<Address>(person, "address")) {
    protected Address onCreate() {
       return addressService.newAddress();
    }
  };

Regards
Sven



On 04/10/2013 03:56 PM, Patrick Davids wrote:
Hi together,

I'm in a discussion with my collegues about extracting models in
constructors of components.

Best practices says: DONT, because of accidently holding references of
extrated objects / out of mems / etc.

But, if we want to have a component containing a form is responsable to
create its own emtpy model, if not created yet.

Is it ok, to extract a model "temporary"?

here an axample:

A person has an address.
An extra component panel with form fields for creating/editing addresses
exists (nested forms pattern).
The AdressComponent gets a model of person.

In case of: person does not have an address, yet.

Is it allowed to extract the person model, to make a service call
somewhere to let create an empty address object for this particular
person and then setting the model object on my own?

We would like to have the knowledge about creation and saving addresses
put toghether in the AddressComponent instead of having the knowledge
about saving inside (onSubmit() of form), and the knowledge about
creation outside the AddressComponent.

kind regards
Patrick
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to