tags:

views:

105

answers:

2

Hi, I have a Wicket Web Page where I create a new Object of class A: A a = new A(User u);

In A I would like to have setter injection, however this is actually not done. I have heard that one must provide an empty constructor but how is it possible to have also a non - empty constructor with setter injection?

A: 

I'm not familiar with Wicket, but I assume that you've got various things on your Wicket web page annotated with @Inject, yes?

So, you have a few options; in order of preference:

  • If you're @Injecting your User, one option is to annotate the constructor of A with @Inject and then in your page, just @Inject either an A or a Provider<A> into web page.
  • You can @Inject into your web page a MembersInjector<A> (call it aMembersInjector) and then after you create your A object call aMembersInjector.injectMembers(a) to cause all the setter injection to happen.
  • You can @Inject into your web page the Injector and call Injector.injectMembers(a) after you create your A.
Daniel Martin
+1  A: 

I'm not exactly sure what you're asking. Regardless, try taking a look at

at see if any examples there shed light on your problem.

Brian Laframboise