ericj
ericj

Reputation: 2301

PropertyModel: what if it's target model changes?

The page has a model,I have done setDefaultModel(). I have a label added to the page:

Label name=new Label("name", new PropertyModel<String>(getDefaultModel(), "name"));
add(name);

Later, the page's model changes. But the property model's target model is still the original page's model.

What can I do to keep the property model updated when the target model changes?

Upvotes: 0

Views: 69

Answers (1)

svenmeier
svenmeier

Reputation: 5681

Usually I advise against using setDefaultModel() or setModel(), exactly because of this type of problems.

Alternatively you can add another indirection:

new Label("name", new PropertyModel<String>(this, "defaultModel.name"));

... or with Wicket 8:

new Label("name", () -> ((Foo)getDefaultModel()).getName());

Upvotes: 2

Related Questions