Again, PAX-WICKET tries to stay as close as possible to Apache Wicket making injection as close to Wickets SpringBean concept as possible. If you're familar with the wicket-spring injection you only need the additional things to go on:
- SpringBean is changed to PaxWicketBean
| The main reason for this change is simply that we needed a more common solution which is a) not touched by other wicket mechanisms which are not OSGi ready yet and b) works for blueprint and spring (and any further framework we plan to add). |
- Injection is always local. Components in Bundle A can only receive beans available in Bundle A's application context_._
| Well, OSGi is a little bit different from your classical web container. While there is only one application context available for all your classes there, in the typical OSGi environment each bundle has its own Application context. With this in mind injection becomes a little bit more complicated of course. Where do we take the beans for which classes, how do we store them and so on. For now the following rules apply: A bean injected in bundle A only takes injections from bundle A; also if you inherit some parts from bundle B and C only bundle A is used to fill the required references. |
- Please be aware that you have to add the following import to your bundle to make injection work: org.ops4j.pax.wicket.util.proxy. (For simplicity please accept this "as is" for now. We'll explain the reasons for this import in more detail here.)
- To inject from a Blueprint context you need to use the name property of the PaxWicketBean annotation. The Blueprint context does not allow type lookup.
- There is no need to add any ComponentInstanciationListener yourself.
- With the injection also testing becomes interesting. This is quite simple and very similar to the Wicket way of testing injection. There's an own PAX-WICKET page discussing this issue.
| Please do not forget that you need to start the corresponding bundles for Spring(DM) or Blueprint in your OSGi engine to make this work. |
Define the Beans
This is plain old spring and blueprint style. Defining the bean looks exactly the same for Spring and Blueprint:
As you might guess already it does not have to be a classic bean only but could also be a <reference> or a <list> or any other named entity in SpringDM or Blueprint.
If you like to see how this works in code you might like to take a look at the code of the SpringDM or Blueprint example.
Injecting the Beans
Simply use the PaxWicketBean annotation to get the beans injected:
If you like to see how this works in code you might like to take a look at the code of the SpringDM or Blueprint example.
What's next?
Basically you've learned everything you need to know about injection. If you want to need more information you might want to read the detailed injection page. Testing injection with PAX-WICKET is explained here.
With this chapter the quickstart guide is basically finished. By now you have all the information and tools you need to write your own Wicket Application based on OSGi. If you need further features or simply want to check what else PAX-WICKET is able to do you may like to continue to the extended quickstart.

