I have two scenes Login.fxml and MainView.fxml and two diferent controllers LoginController.java and MainViewControler.java
In LoginController I do the whole process to login and get the value of JSessionID and store it in a object, like below:
loginGateway = loginGateway(gateway);
Now in MainViewController I need to use the this object (loginGateway) to getJSessionID and make other requests to the server. But how can I acess this object in another Controller Class (MainViewController.java) ????
Update 2023
As noted in the referenced question:
An alternate solution to that presented here is to use MVC, similar to as documented in:
The solution presented here is still perfectly OK, but you might have a bit more flexibility (and a bit more complexity) by adopting the MVC approach instead.
Use a variation on the solution in Passing Parameters JavaFX FXML.
Setup a
LoginManagerwhich has a reference to both theLoginControllerand theMainViewController.loginManagercreates a login screen using theloginControllerand passes a reference to itself to theloginController.loginControllernotifies theloginManagerof the loginsessionID.loginManagercan then create aMainViewController, passing themainViewControllerthesessionIDand replacing the scene contents with the main view.Here is a link to some sample code to demonstrate this approach.

