Wicket 想要序列化我的面板
当我访问 Wicket 应用程序的特定页面时,我收到 NotSerializedException:
java.io.NotSerializableException: my.package.MyPanel$1
但我无法解释为什么 wicket 应尝试序列化面板。有什么想法吗?
我不知道它是否有帮助,但这是我用来添加面板的代码:
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());
}
});
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());
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Wicket 将许多内容序列化到会话中,作为其处理集群方法的一部分。
Wicket 中的几乎所有内容(最终)都扩展了
Component
,后者实现了IClusterable
,后者又扩展了Serialized
。因此,在 Wicket 中创建的面板等组件需要可序列化。常见的做法是创建
LoadableDetachableModel
类,使用仅在会话中存储密钥并使用该密钥重新加载的逻辑来包装普通业务对象。如果您使用此类模型作为组件中的字段而不是完整的业务对象,那么您对会话内存的压力就会小得多。
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 implementsIClusterable
which extendsSerializable
. 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.