-
Notifications
You must be signed in to change notification settings - Fork 104
Deviating FXML location
With mvvmFX, a typical "View" consists of a FXML file and a CodeBehind class. To load such a View you can either include the FXML file into another FXML file with the <fx:include src="...">
tag or directly load the View with the FluentViewLoader.
When using the FluentViewLoader to load a view, you provide the CodeBehind class reference to the view loader and the FXML file is resolved by following a set of [Naming Conventions], mainly that the CodeBehind class has to have the same name as the FXML file.
However, in certain situations it may be either not possible or unconvinient to follow these naming conventions. Starting with version 1.7 you can use the annotation @FxmlPath (TODO add link to javadoc) to bypass the naming conventions and define a deviating location for an FXML file.
With @FxmlPath
you can define an absolute path to the FXML file (including file extension) for a specific CodeBehind. See the following file structure and the example code to load the View:
└── com
└── example
├── myapp
│ └── MyCodeBehind.java
│ └── MyViewModel.java
└── some
└── other
└── path
└── OtherName.fxml
MyCodeBehind:
@FxmlPath("/com/example/some/other/path/OtherName.fxml")
public class MyCodeBehind extends FxmlView<MyViewModel> {
...
}
With this annotation the View can be loaded with the FluentViewLoader
as usual:
FluentViewLoader.fxmlView(MyCodeBehind.class).load();
Notice: The
@FxmlPath
annotation is only evaluated when loading a View with theFluentViewLoader
. It is not used when a View is embedded in another FXML file with<fx:include src="" />
. Instead thesrc
attribute of the include-tag determines the path to the FXML file in this case.
We encourage you to stick with the naming conventions and to not use @FxmlPath
if possible. @FxmlPath
is
intended as a tool to enable certain advanced setups.
There are at least two situations where @FxmlPath
can be useful:
- If you can't control the file structure or naming of the FXML or CodeBehind.
- With the annotation it is now possible to have multiple CodeBehind classes for a single FXML file.