[REVIEW] Make controller instantiation customizable

Greg Brown greg.x.brown at oracle.com
Wed Dec 14 13:25:12 PST 2011

> What about one of the following in the FXML (your choice which one);
> <HBox fx:controller>
> <HBox fx:controller="">
> <HBox fx:controller="default">
> <HBox fx:default-controller>

FYI, I don't believe the first and last options are valid XML, so I think those are out in any case.

But I guess I'm still not clear on what you mean by "default". I understood the idea of providing a controller to the loader rather than having the loader instantiate one, but I don't think I could describe what fx:controller="default" means.

> 1. The FXML declares named/typed variables that the loader can supply.

FXML isn't typed, so this doesn't make a lot of sense to me. But as we have already discussed, you can pass values to the loader via the namespace, even before you call the load() method.

> 2. The FXML 'implements' a view interface. Tooling would generate the interface instead of the controller class. 

Again, FXML isn't typed, so it can't really "implement" anything. Also note that the current set of tooling doesn't actually get involved in any code generation, only markup. That's one of the benefits of the FXML approach - it avoids the messiness typically associated with GUI builder-generated code.

I'm really struggling to understand the use case. Couldn't you do something like this, for example?

public interface MyController {

public class MyControllerImpl implements MyController {

<HBox fx:controller="com.foo.MyController">

Your controller factory's implementation of getController() could return an instance of MyControllerImpl or whatever implementation makes sense.


More information about the openjfx-dev mailing list