I try to make an application in JavaFX with a left panel with some buttoms and a right panel where I load diferent panels. Both panels (left/right) are in a BorderPane. Each button when is pressed, load a fxml in right panel. If I press other buttom, the panel change and load other fxml.
Base on this schema, I have 2 questions:
How can I save state of panels?
Example: When press btn1, loads panel1 wich contains for example a texfield and write my name. Next, I press btn2 and loads panel2 with other controls. And finally, I return to panel1 but I need to get the panel whith the textfield contains my name no an empty textfield (and vice versa if I have controls in panel2 and have something and change to that panel from another).
How can I share information between panels?
Example: I load in panel1 a list of users (from DB), if user change to panel2, I show in a label the sum of all users but I want to reuse the same list to count I don´t want to execute the same query.
I try to use a HashMap in window controller (with have associate fxml with window structure). When a panel loads, I check if controller exists in the HashMap if not, I create and instance and save, next time that user use the same panel, controller is take from the hashmap and load with the same state than last time. This works but I have one problem, How to exchange information between other panels controllers? I know that I can pass hashmap to all controllers but I prefer to use dependency-injection.
I don´t want to use Spring framework, I try with DataFX but I don´t know how to do?