Search code examples
javamodel-view-controllerjavafxcontrollerspass-data

How to store data within javafx application


It is my first post so it might be little inappropriate. I try to develop an application in JavaFX to regain my programming skills from past years.

I trying to create a JavaFX application that consists several views and controllers like Controller1,View1,Controller2,View2 and so go on. I have also included Main class for startup process in my application. I try to develop this training app with MVC design pattern.

My question is: how to store data between Controllers and views ? Curently I have my data stored in a list of objects i.e Event within Controller1 (MainwindowController) and then if I want to do something with that list like add from other window new element to it I'm passing the list by the Controller2 constructor. I found that some way troublesome becaues I'm passing whole list between Controller1 and Controller2 but I really don't want to do it that way.

Is there a way to store data that would be accessible for all Controllers in a instance without aimlessly passing bunch of data between them ?

I know that is a silly question but for me it is quite troublesome to figure it out.

Many thanks in advance for any tips of clues :)


Solution

  • If you are using the mvc pattern your data must be in model layer and call it from controllers. If your data is in controller class and you dont want to pass all data between them you can use static members.