You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

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, and so forth.

Customize

Extend ObjectFactory

Customized ObjectFactory must extend ObjectFactory or any of its descendants and have a default, no-argument constructor.

To register a customized ObjectFactory, add or edit an entry in struts.properties

 struts.objectFactory=foo.bar.MyCustomObjectFactory

where foo.bar.MyCustomObjectFactory is the custom object factory.

public class MyObjectFactory extends ObjectFactory {
    .....
}

Define dedicated builder

If you want to just extend one part of ObjectFactory, ie. change how Results are build, you can implement dedicated interface below and register it with dedicated name, see Extension Points for more details. All these builders are available as from version 2.3.16 when StrutsObjectFactory or its descendants is defined as struts.objectFactory - basically this should work with default Struts 2 installation and with the Spring plugin as well.

List of Builder interfaces:

  • ResultBuilder - dedicated interfaces used to build Result
    • StrutsResultBuilder it's internal implementation which checks if Result implements ParamNameAwareResult to restrict names of parameters set on the instance of Result.

Next: ActionMapper

  • No labels