[REVIEW] Make controller instantiation customizable

Richard Bair richard.bair at oracle.com
Tue Dec 13 12:44:04 PST 2011


Hi Greg,

Is there also some API added to FXMLLoader to allow registration of a ControllerFactory? Beyond FXMLLoader, is there any other public API added?

Thanks
Richard

On Dec 13, 2011, at 11:22 AM, Greg Brown wrote:

> This is a review request for RT-17268:
> 
> http://javafx-jira.kenai.com/browse/RT-17268
> 
> In FXML 2.0, the caller did not have any control over controller creation. This prevented an application from using a dependency injection system such as Guice or Spring to manage controller initialization. This change adds a ControllerFactory interface to facilitate delegation of controller construction:
> 
> public interface ControllerFactory {
>    public Object getController(Class<?> type);
> }
> 
> When an instance of ControllerFactory is provided to FXMLLoader, the loader will delegate controller construction to the factory. An implementation may return null to indicate that it does not or cannot create a controller of the given type; in this case, the default controller construction mechanism will be employed by the loader. Implementations may also "recycle" controllers such that controller instances can be shared by multiple FXML documents. However, developers must be aware of the implications of doing this; primarily, that controller field injection should not be used in this case since it will result in the controller fields containing values from only the most recently loaded document.
> 



More information about the openjfx-dev mailing list