If this is the case then why aren't components effected?

D/


On 6/25/09 2:04 PM, "Mauro Ciancio" <[email protected]> wrote:

On Wed, Jun 24, 2009 at 1:38 PM, Aaron Dixon <[email protected]> wrote:

>
> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
> Unable to serialize class:
> com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94
> Field hierarchy is:
>  2 [class=com.mycompany.pages.MyPage, path=2]
>    private com.mycompany.dao.MyDao
>
> com.mycompany.pages.MyPage.myDao[class=com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94]
> <----- field that is not serializable
>    at
>
> org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:342)
>    at
>
> org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:610)
> ...
> ====
>
> Has anyone else noticed this?
>

  Yes, it happens because the injected class isn't Serializable and when
your page
is serialized the exception is thrown.
  You could use for example a
LoadableDetachableModel<http://wicket.apache.org/docs/wicket-1.3.2/wicket/apidocs/org/apache/wicket/model/LoadableDetachableModel.html>to
detach your DAO when
your page is serialized.
  Guice also comes with an interface named Provider<T>. This could helps
because it
dont hold a reference to your un-serializable object.

Example:

class MyPage extends Page {
  LoadableDetachableModel daoModel = new loadable() {
    object get() {
          return new dao();
     }
  };

  void something() {
     mydao = daoModel.getObject();
     //stuff
  }

  void ondetach() {
    super.ondetach()
     daomodel.detach();
   }
 }

HTH
Cheers!
--
Mauro Ciancio

Reply via email to