Package org.apache.wicket.guice
Class GuiceWebApplicationFactory
- java.lang.Object
-
- org.apache.wicket.guice.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 yourWebApplication.init()
method - this factory will do that for you automatically.- Author:
- Alastair Maw (almaw)
-
-
Field Summary
Fields Modifier and Type Field Description static String
STAGE_PARAMETER
-
Constructor Summary
Constructors Constructor Description GuiceWebApplicationFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WebApplication
createApplication(WicketFilter filter)
Create application objectvoid
destroy(WicketFilter filter)
Called when the filter instance that used this factory is destroyed
-
-
-
Field Detail
-
STAGE_PARAMETER
public static final String STAGE_PARAMETER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GuiceWebApplicationFactory
public GuiceWebApplicationFactory()
-
-
Method Detail
-
createApplication
public WebApplication createApplication(WicketFilter filter)
Description copied from interface:IWebApplicationFactory
Create application object- Specified by:
createApplication
in interfaceIWebApplicationFactory
- Parameters:
filter
- the wicket filter- Returns:
- application object instance
- See Also:
IWebApplicationFactory.createApplication(WicketFilter)
-
destroy
public void destroy(WicketFilter filter)
Called when the filter instance that used this factory is destroyed- Specified by:
destroy
in interfaceIWebApplicationFactory
- Parameters:
filter
- the wicket filter
-
-