ObjectFactory has the sole responsibility of creating objects needed by Struts2. It is how Struts2 does its integration All objects created by the framework are instantiated by the ObjectFactory. The ObjectFactory provides the means of integrating the framework with IoC containers like Spring, Pico, Plexus etc, and so forth.
Customize
Extend ObjectFactory
Note |
---|
Customized ObjectFactory must extends off extend ObjectFactory or any of its decendant descendants and have a default, no-argument constructor. |
To have register a customized ObjectFactory, have the following add or edit an entry in struts.properties
Code Block |
---|
struts.objectFactory=foo.bar.MyCustomObjectFactory
|
where foo.bar.MyCustomObjectFactory is the custom object factory.
Code Block |
---|
public class MyObjectFactory extends ObjectFactory { ..... } } |
Define dedicated factory
If you want to just extend one part of ObjectFactory, ie. to change how Result Types are build, you can implement ResultFactory
interface and register it with dedicated name, see Extension Points for more details. Original ObjectFactory will use these dedicated factories to do the work. It's already done this way - the original functionality of ObjectFactory was extracted to separated classes which implements the interfaces below. Check the source of ObjectFactory to see more details. All these factories are available as from version 2.3.16.
List of Factory interfaces:
ResultFactory
- dedicated interfaces used by ObjectFactory to create Result TypesStrutsResultFactory
it's internal implementation which checks if Result implementsParamNameAwareResult
interface to restrict names of parameters set on the instance of Result, see Result Types for more info.
ActionFactory
- dedicated interface used by ObjectFactory to actionsInterceptorFactory
- dedicated interface used by ObjectFactory to create interceptorsValidatorFactory
- dedicated interface used by ObjectFactory to create validatorsConverterFactory
- dedicated interface used by ObjectFactory to create instances of TypeConverterUnknownHandlerFactory
- dedicated interfaces used by ObjectFactory to create instances of Unknown Handlers (as from version 2.3.18)