Page Factory
Why should I use a Page Factory?
A page factory is an OSGi Service registered responsible for creating specific pages if requested. Typically it's simply created by reflection instantiating a class. This is quite simple but has the disadvantage that you couldn't give any params to the constructor (except for using page parameters). So, if you would like to create different classes for different situations without using page params an option is to use the PageFactory.
How does it work?
Basically Wicket requests a Page from a PageFactory if one should be created. By default Wicket tries to simply create a class by using reflection. Pax-Wicket changes this behavior slightly by first looking up if there is any service registered responsible for creating the page; otherwise it will fallback to reflection.
Always keep in mind that all "binding" between components and the right application in the OSGi context is done via the pax.wicket.applicationname property. This is also whats done in all the examples; differently depending on the system you're using, but still.
How to do it?
This depends on the environment you're working on.
Plain OSGi API
If you're working with the plan OSGi API all required is the following:
public class Activator implements BundleActivator {
...variables...
public void start(BundleContext bundleContext) throws Exception {
...other calls...
pageFactory = new AbstractPageFactory<SimpleTestPage>(bundleContext, "application.name", "page path", "pageId") {
public Class<SimpleTestPage> getPageClass() {
return MyPageIWouldLikeToCreateHere.class;
}
public SimpleTestPage createPage(PageParameters params) {
return new MyPageIWouldLikeToCreateHere();
}
};
pageFactory.register();
...other calls...
}
public void stop(BundleContext context) throws Exception {
...other disposals...
pageFactory.dispose();
...other disposals...
}
}