0

It seems that I have some sort of basic question, but I cant figure out how to solve it, I tryed everything and atm. I am in this rage mode where nothing seems to work and the concentration fades.

I have my UserController in this UserController I have a ComboBox which works perfect, I need to pass the selected city from this ComboBox as a String argument to a method in my MuseumController.

It works for the Label but not for the method which I use in the MuseumController.

Here is the relevant code from the UserController:

public void SearchM(ActionEvent event) {

    try {
            ((Node) event.getSource()).getScene().getWindow().hide();

            Stage primaryStage = new Stage();

            FXMLLoader loader = new FXMLLoader();

            Pane root = loader.load(getClass().getResource("/application/M_in_City.fxml").openStream());

            MuseenController museenController = (MuseenController) loader.getController();
            museenController.GetCityName(txtComboboxStadt.getValue());
            //museenController.GetOnlyCityName(txtComboboxStadt.getValue());
            Scene scene = new Scene(root);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();

    } catch (IOException e) {

        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

In this UserController im passing the value succesfully into the Label from my MuseumController, my first Idea was, why not take the Label (because the label already displays the needed city) and get the city from there, didnt worked because it shows me somehow only the default label not the updated one with the city name.

MuseumController where I have a function which needs an ObserverList and a String argument (THE CITY), the function works perfectly, I tried it with a manual string:

@FXML
private Label MuseenInStadtLbl;

@FXML
private ListView<String> ListViewMuseen;

@Override
public void initialize(URL location, ResourceBundle resources) {    
    museenInStadtModel.FillListViewStadt(ListViewMuseen, "Düsseldorf");
}

//public String only_cityname;
/*
public String GetOnlyCityName(String city) {
    return city;
}
*/

public void GetCityName(String city) {
    //only_cityname = city;
    MuseenInStadtLbl.setText("Museen in der Stadt: " + city);
}

So I need to replace "Düssedorf" with the Value from the ComboBox or the city argument from the method GetCityName

I tryed passing only the string which always resulted in setting the string to null, its because of the initialize method, but how to do it then?

This thread sadly didnt helped: Similar Problem on StackOverFlow

I tryed to provide only relevant code, the FillListViewStadt method works perfectly. If I missed something tell me and I update.

Summarized: How do I pass the selected value from the combobox in usercontroller as a string argument into the initialize from museencontroller into the function FillListViewStadt and replace the manualy enetred "Düsseldorf" with it.

2
  • 1
    the initialize() method is called on loader.load(), so way before you have the chance to pass any parameters. The correct way would be to create a different method (like you did with GetCityName()) and pass the parameters there. Commented Mar 23, 2016 at 13:00
  • @Moh-Aw thanks, thats it. I moved the whole method from initialize into the GetCityName. Now it works, I was dancing already around this solution, but in rage mode you forget many simple things. ;) If you create an answer, I accept it. Commented Mar 23, 2016 at 13:09

1 Answer 1

2

The initialize() method is called on loader.load(), so way before you have the chance to pass any parameters. The correct way would be to create a different method (like you did with GetCityName()) and pass the parameters there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.