Skip to content

Load view (only) when controller is injected #175

@hallvard

Description

@hallvard

If I understand this extension correctly, it loads an instance of all controller/fxml pairs (when the controller is annotated with @FxmlView that is) during startup. I find this confusing and would prefer having more control of when controller/fxml pairs are loaded. Why not allow injecting the controller (or creating it with Instance.get()) and autoloading the corresponding fxml view only then?

The behaviour I envision is a bit like the following:

class MyController {

  @Inject FXMLLoader fxmlLoader;

  @PostConstruct
  void loadView() {
    fxmlLoader.setController(this);
    fxmlLoader.setLocation(lookupFxmlResourceWithStandardRules(this.getClass()));
    fxml.load();
  }

  ...
}

Later you just @Inject MyController myController to create (or reuse depending on the controller's scope) the controller instance and auto-load the FXML.

The point is loading the view and having the usual FXML-injection done just after the controller is fully created. This way, the fxml loading process is hidden, while still giving you control of when it happens (you can annotate the MyController with any scope, @dependent, @ApplicationScoped or other). The controller can allow you to get nodes in the view, so they can be attached to the scene graph (stage, scene or lower down).

I only have a rough understanding of quarkus extensions, I imagine it would be possible to auto-augment @FxmlView-annotated classes with the above field and @PostConstruct method (or similar that gives that effect), to make this work? If it's possible, I think it may remove the need for FxmlRepository, thus simplifying the extension, but I may be wrong.

This seems related to #75 as it also is about giving more control of when loading is done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions