Class GuiceWebApplicationFactory

  • All Implemented Interfaces:
    IWebApplicationFactory

    public class GuiceWebApplicationFactory
    extends Object
    implements IWebApplicationFactory
    Implementation of IWebApplicationFactory that pulls the WebApplication object out of a Guice Module. Configuration example:
     <filter>
       <filter-name>MyApplication</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>module</param-name>
         <param-value>com.company.MyGuiceModule,com.company.MyOtherGuiceModule</param-value>
       </init-param>
       <init-param>
         <param-name>wicket-guice.stage</param-name>
         <param-value>DEVELOPMENT</param-value>
       </init-param>
     </filter>
     
    This factory will create an Injector configured using the Guice Module implementation you pass it above. Multiple modules can be specified by naming multiple classes separated by a comma. The Guice Module (MyGuiceModule in the example above) needs to bind WebApplication.class and provide a concrete implementation of it. The stage used when creating the Injector may be specified by the optional wicket-guice.stage parameter. When this parameter is not present this factory does not use specify a Stage when creating the Injector. This parameter can also be set as a context parameter to provide configuration for all instances in the web application. Alternatively, you can dig the Injector out of the ServletContext as an attribute, like so:
     <filter>
       <filter-name>MyApplication</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>GuiceInjector</param-value>
       </init-param>
     </filter>
     
    NB: You no longer have to add a GuiceComponentInjector manually in your WebApplication.init() method - this factory will do that for you automatically.
    Author:
    Alastair Maw (almaw)