Wicket 想要序列化我的面板 [英] Wicket wants to serialize my Panel

查看:61
本文介绍了Wicket 想要序列化我的面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我访问 Wicket 应用程序的特定页面时,我收到 NotSerializableException:

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

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

但我无法解释为什么 wicket 应该尝试序列化 Panel.有什么想法吗?

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());
        }
    });

推荐答案

Wicket 将许多内容序列化到会话中,作为其处理聚类的方法的一部分.

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

Wicket 中的几乎所有东西(最终)都扩展了 Component,它实现了 IClusterable,它扩展了 Serializable.因此,在 Wicket 中创建的面板等组件需要可序列化.

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.

一种常见的做法是创建 LoadableDetachableModel 类,用逻辑包装您的普通业务对象,该逻辑仅在会话中存储一个键并使用该键重新加载.

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.

这篇关于Wicket 想要序列化我的面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆