Wicket wants to serialize my Panel

2019-05-25 06:11发布

When I access a specific page of my Wicket application, I get a NotSerializableException:

java.io.NotSerializableException: my.package.MyPanel$1

But I can't explain why wicket should try to serialize the Panel. Any idea?

I don't know if it helps, but here is the code I use to add the panel:

final User profileUser = ...;
final IModel<User> loggedInUser = ...;
add(new MyPanel("panelid", new Model<MyObject>(new MyObject()))
    {
        @Override
        public boolean isVisible()
        {
            return profileUser != null && profileUser.equals(loggedInUser.getObject());
        }
    });

1条回答
看我几分像从前
2楼-- · 2019-05-25 07:09

Wicket serializes many things into the session as part of its approach to dealing with clustering.

Just about everything in Wicket (eventually) extends Component which implements IClusterable which extends Serializable. So components such as panels that created in Wicket need to be serializable.

A common practice is to create LoadableDetachableModel classes wrapping your normal business objects with logic that stores only a key in session and reloads using that key.

If you use such models as fields in your components instead of the full business objects you'll strain the session memory much less.

查看更多
登录 后发表回答