I'm struggling with a javafx + weld problem.
I'm building application that should switch scenes/views. Application is using weld CDI.
I was trying several approaches and none of them is working. Currently my application is based on a solution from this link https://dzone.com/articles/fxml-javafx-powered-cdi-jboss.
This method (copied from mentioned solution) works just fine.
public void launchJavaFXApplication(@Observes @StartupScene Stage s) {
mainStage = s;
InputStream is = null;
try {
is = getClass().getResourceAsStream("Views/LoginView.fxml");
Parent root = (Parent) fxmlLoader.load(is);
s.setTitle("Login");
s.setScene(new Scene(root, 900, 600));
s.show();
} catch (IOException e) {
throw new IllegalStateException("cannot load FXML login screen", e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
}
It loads first screen, but then I'm trying to switch view to another fxml file that is located side by side with mentioned LoginView, the getClass().getResourceAsStream("Views/LoginView.fxml") returns null. The second view (MainView) is being fired by using button on the login view. I was trying to load MainView instead of LoginView in the launchJavaFXApplication method and it works just fine.
The second problem: when trying to place fxml control (even a very simple one without controller) inside the fxml file loaded with launchJavaFXApplication method, InputStream is also null.
If something is missing please ask and I can put some more code samples if it may clarify the situation.
regards, Bartek