I have done a lot of experimentation at the moment and I am using CDI
dependency injection now for a simple wicket project. It is based on the
code at utils.wamblee.org (wicket/inject).

The issue I am running into is the following. I am creating a detachable
entity object which is simply a detachable model that safes the primary key
in onDetach() + sets the object to null.
It loads the object from persistent storage using entityManager.find(class,
key) in the get() method (if not yet initialized).

The detachable model is constructed using an entity manager obtained using
CDI. However, in the following scenario, things go wrong: (1) edit an entity
in a form, (2) click ok, (3) browser back.

What happens is that I get a NullPointerException in EntityManagerWrapper on
line 314 on glassfish v3. What is actually happening here is that the
detachable model is being serialized but the EntityManagerWrapper (the
contextual that delegates to the actual entitymanager to use) has transient
fields which become null after deserialization. The EntityManagerWrapper is
declared Serializable but in fact it isn't.

Now, I have to do two things. First I have to report an issue on glassfish
v3. I think the entity manager wrapper should be truly serializable and not
just declared serializable.  Second, I need to work around this problem. The
solution I am thinking of is to use a simple utility that provides a truly
serializable entity manager that delegates to an entity manager obtained
using CDI. That would solve the problem with the detachable.

However, there is one more issue which is the injection setup in the
application. I still need the injection at component instantiation to allow
use of injected objects in the constructor. But I still have a question
whether it would be required to also use a IComponentOnBeforeRenderListener
to do an additional injection in the onBeforeRender() method. The only
reason I would need to do this is when pages in wicket are serialized as
well. Do I need to take page serialization into account? Is there also a
callback in wicket to listen for component serialization and
deserialization?

Reply via email to