How can I pass variables between two controllers that are initializable? After logging in, the username is null in the second page because it already initialized(I am using a framework). Can I run a method to load the variables after initialization?
So here is a code snippet: logincontroller
public static String myusername;
public static String myaccount;
@FXML
private JFXTextField username;
@FXML
public void makeLogin(ActionEvent event) {
Document query = new Document();
query.put("userName", username.getText());
FindIterable<Document> docs = userCollection.find(query);
if(docs != null){
if(detailsmatch(username, password)){
String theaccount = (String) doc.get("account");
USERSingleton.getInstance().setusername(username.getText());
USERSingleton.getInstance().setaccount(theaccount);
myusername = USERSingleton.getInstance().getusername();
myaccount = USERSingleton.getInstance().getaccount();
myScreenPane.setHomeScreen("home");
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
@Override
public void setScreenPane(screenPane screenPage) {
myScreenPane = screenPage;
}
}
So I would like to get the account variable in the homecontroller from the logincontroller. Like:
homecotroller
System.out.println(logincontroller.myaccount);
System.out.println(USERSingleton.getInstance().getaccount());
. .