Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
public FooPanel(String id,IModel<User> userMdl) {
        super(id.userMdl);
        User user = getModelObject();
        // Doh! user is serialized with each page view, since the PropertyModel holds a reference!
        add(new Label("name",new PropertyModel(user,"screenName")));
}

Here

...

is

...

the

...

correct

...

way

...

to

...

do

...

this:

Code Block
public FooPanel(String id,IModel<User> userMdl) {
        super(id.userMdl);
        add(new Label("name",new PropertyModel(userMdl,"screenName")));
}

The

...

PropertyModel

...

holds

...

a

...

reference

...

to

...

the

...

Model

...

which

...

fetches

...

the

...

User

...

on

...

each

...

page

...

view.

...

That

...

way

...

the

...

User

...

object

...

is

...

always

...

fresh

...

and

...

is

...

not

...

serialized

...

with

...

the

...

page.

...

Anti-Pattern #3.

Code Block
public FooPanel(String id,User user) {
        // The stale User object will be in your session
        // for the life span of the stateful page.
        super(id.new Model(user));
}

...