hi!
so, im using wicket together with guice for DI.
i really wondered that the correct approach is here.
at first i thought it way easy to do this, but it turns out it is more complicated..- at least more complicated to understand.
my typical page looks like this:

public class StartPage extends WebPage {
private transient EmkDao dao;

   @Inject
   public void setDao(EmkDao dao) {
       this.dao = dao;
   }


   public EmkDao getDao() {
       return dao;
   }

public Start() {
add( Components that use the dao in various ways (models, onclick etc);
}
}

this seems to work well, in simple cases. BUT! as soon as i press browser-back and reload most likely the dao member has become null. -> NPE

the expected behavior would be: transient fields are re-injected whenever the page is deserialized. obviously this is not the case. im surprised, that my StartPage is often a different instance (as seen in the debugger) , when using browser-back-reload, but the setter annotated with @Inject is not called twice.

since WebPage is Serializable and most injected objects are not (they often contain references to non-serializable classes) they have to be declared transient.

I use the following guice config:


<filter>
   <filter-name>WicketApplication</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
   <init-param>
     <param-name>applicationFactoryClassName</param-name>
<param-value>org.apache.wicket.guice.GuiceWebApplicationFactory</param-value>
   </init-param>
   <init-param>
     <param-name>injectorContextAttribute</param-name>
     <param-value>com.google.inject.Injector</param-value>
   </init-param>
 </filter>

with
bind(WebApplication.class).to(MyWicketApplication.class) in my Module.

i also tried the configuration described at http://www.wideplay.com/wicketwithwarp-servlet with a simple WicketFilter (without the GuiceWebApplicationFactory) and Integrathe.with(this) in the WicketApplication, with the same result.

As I'm writing this mail, it turns out, it appears to work if i just omit the "transient" keyword. i wonder: what will that do to wicket pages? will i prevent them to serialize any more? why doesn't it throw a NotSerializableException ? then i have to use @SuppressWarnings({"NonSerializableFieldInSerializableClass"}) for IntelliJ to omit the warning.
somehow i am missing a coherent documentation on wicket+IoC on this matter.

best regards,
Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to