Am 27.09.2012 09:51, schrieb Martin Grigorov:

Hi,

a dont care about the type issue here.. Maybe i can explain it again in an other way:

APanel uses model instance A and the label uses a property model instance P which uses a reference to model instance A.

After calling APanel.setDefaultModel(B) APanel uses model instance B,but label uses model instance P which uses model instance A as before. So the label does not see any changes, because no one tells the model instance P, that it should use B instead of A. I think, there are rare cases for such a usage.

thanks
Michael

Hi,

In this particular code I think the "problem" is PropertyModel, since
it brings the type unsafety.

Another solution is to make Component<T>, this way we can remove
#setDefaultModel() and have #setModel(IModel<T>) only and such
problems will go away.
But as discussed in early Wicket 1.4 days this will lead to more
typing. With Java 7 diamonds it is half the typing though.

For now you can use GenericPanel, GenericPage and all FormComponent.

On Thu, Sep 27, 2012 at 10:41 AM, Michael Mosmann <mich...@mosmann.de> wrote:
Am 27.09.2012 09:01, schrieb Martin Grigorov:
Hi,

I think, there is a little difference in using setDefaultModel and
setDefaultModelObject .. the first one sets a new model instance, the second
only change the value in the existing model. Some pseudo-code:

class APanel extends Panel {
     APanel(String id,IModel<Some> model) {
         super(id,model);

         add(new Label("name",new PropertyModel(getDefaultModel(),"name"));
     }
}

If you replace the value in model, everything is fine and works as expected.
If you call setDefaultModel you might think, that everything is fine, but
its not. A child component does not use getParent().getDefaultModel() to get
these changes. I saw a lot of code like this, which leads to trouble, if you
change the model and not the value.

If there is no benefit in using setDefaultModel over setDefaultModelObject i
would like to remove this method. This could prevent many "you might not got
the full picture how to use wicket the right way" errors.

Michael


Hi,

Most of the time it is recommended to use a dynamic model, so there is
no reason to replace the component's model.
Component#setDefaultModel() gives you semi-dynamic nature - you can
replace the model completely with a new one. Same with
#setDefaultModelObject().

What is the problem you face with it ?

On Thu, Sep 27, 2012 at 9:57 AM, Michael Mosmann <mich...@mosmann.de>
wrote:
Hi,

is there any usefull application of Component.setDefaultModel(...)? IMHO
this Method is the cause for much trouble without any benefit. But maybe
i
did not understand when someone should replace a component model...

thanks
Michael





Reply via email to