blob: 3a6081145574572a792c44aef2df057f81799104 [file] [log] [blame]
h1. Serialization
With wicket everything is serialized. Remember this. This great framework provides support for stateful elements but there is a price - we can not use not serializable objects. Don't be afraid - we still might read them but we have to follow few rules.
# First of all, do not assign not serializable objects to fields
# Do not create final variables to use in anonymous classes, it will work, but you'll get mess in logs. Look at code below
{code:java}
final Entity en = dao.find(id); # broken!
add(new Form<Entity>() {
public void onSubmit() {
dao.save(getModelObject());
}
});
{code}
As you see in marked line of this code we declared *en* variable as a final. This means that JVM will try to write reference to this variable in ObjectOutputStream, and as you might expect - you will get NotSerializableException
# For list views and repeaters use LoadableDetachableModels, in IDataProvider implementations/extensions remember to return LoadableDetachableModel.
As long as you follow there rules you might sleep peacefully. In any case, when you will meet mr. NotSerializable, make own life easier and use -Dsun.io.serialization.extendedDebugInfo=true parameter to add path to not serializable element in stack trace. With these you'll get message like this:
{code}
Caused by: java.io.NotSerializableException: org.apache.felix.framework.ServiceRegistrationImpl$ServiceReferenceImpl
- field (class "org.apache.karaf.webconsole.osgi.internal.bundle.DetailsPage$4$1", name: "val$reference", type: "interface org.osgi.framework.ServiceReference")
- object (class "org.apache.karaf.webconsole.osgi.internal.bundle.DetailsPage$4$1", [MarkupContainer [Component id = serviceInUseProperty]])
- element of array (index: 1)
- array (class "[Ljava.lang.Object;", size: 2)
- field (class "org.apache.wicket.MarkupContainer", name: "children", type: "class java.lang.Object")
- object (class "org.apache.wicket.markup.html.list.ListItem", [MarkupContainer [Component id = 0]])
- element of array (index: 0)
- array (class "[Ljava.lang.Object;", size: 7)
- field (class "org.apache.wicket.MarkupContainer", name: "children", type: "class java.lang.Object")
- object (class "org.apache.karaf.webconsole.osgi.internal.bundle.DetailsPage$4", [MarkupContainer [Component id = servicesInUse]])
- element of array (index: 8)
- array (class "[Ljava.lang.Object;", size: 9)
- field (class "org.apache.wicket.MarkupContainer", name: "children", type: "class java.lang.Object")
- root object (class "org.apache.karaf.webconsole.osgi.internal.bundle.DetailsPage", [Page class = org.apache.karaf.webconsole.osgi.internal.bundle.DetailsPage, id = 14, version = 0])
{code}
instead of
{code}
Caused by: java.io.NotSerializableException: org.apache.felix.framework.ServiceRegistrationImpl$ServiceReferenceImpl
{code}