1

estou tendo um problema ao tentar passar parâmetros para qualquer controller, usando como exemplo dois de meus controllers:

O controller1 possui a seguinte função para navegar para controller2:

public void navegarParaTelaProfessor(Professor professor){
        try{
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/View/telaProfessor/professorTela/T1 Professor.fxml"));
            Parent root = fxmlLoader.load();

            (((ControllerT1) fxmlLoader.getController())).setStage(stage, professor, new FachadaProfessor());

            Scene scene = new Scene(root);
            stage.setScene(scene);
            stage.setTitle("Professor");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

E no controller2 temos a função que armazena os parâmetros passados:

public void setStage(Stage stage, Professor professor, FachadaProfessor fachadaProfessor) throws IOException, ClassNotFoundException {
        this.stage = stage;
        fachadaProfessor.recuperarTurmasProfessor(professor);
        this.professor = professor;
        this.fachadaProfessor = fachadaProfessor;
        this.turmas = FXCollections.observableArrayList(this.professor.getTurmasArrayList());
    }

Logo após passar os parâmetros é feita a mudança da scene e a tentativa de atualização do layout, porém, todos os objetos estão nulos ao entrar no controller:

inserir a descrição da imagem aqui

Porém, durante a chamada da função dos parâmetros todos os objetos são salvos corretamente: inserir a descrição da imagem aqui

Alguma ideia do que possa estar fazendo de errado? Código completo do controlador2:

package Controller.ControllersTelaProfessor;

import Classes.pessoas.Professor;
import Classes.turmas.Turma;
import Controller.ControllerLogin;
import Model.fachada.FachadaProfessor;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class ControllerT1 implements Initializable {
    private String mensagem;
    private FachadaProfessor fachadaProfessor;
    private Professor professor;
    private Turma turmaSelecionada;
    private ObservableList<Turma> turmas;

    private Stage stage;


    @FXML
    private ListView<Turma> listaTurmas;

    @FXML
    private void setTurmaSelecionada(){
        Turma turma = this.listaTurmas.getSelectionModel().getSelectedItem();

        this.turmaSelecionada = turma;
    }

    @FXML
    public void voltar() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/View/telaLogin/TelaLogin.fxml"));
        Parent root = fxmlLoader.load();

        ((ControllerLogin) fxmlLoader.getController()).setStage(this.stage);

        Scene scene = new Scene(root);
        this.stage.setScene(scene);
        this.stage.setTitle("Login");
    }


    @FXML
    public void continuar(){
        try{
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/View/telaProfessor/professorTela/T2 Professor.fxml"));
            Parent root = fxmlLoader.load();

            ((ControllerT2) fxmlLoader.getController()).setStage(this.stage);
            ((ControllerT2) fxmlLoader.getController()).setParametros(this.fachadaProfessor, this.turmaSelecionada, this.professor);

            Scene scene = new Scene(root);
            this.stage.setScene(scene);
            this.stage.setTitle(turmaSelecionada.getApelido());

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    private void iniciarLayout(){
        listaTurmas.setItems(turmas);
    }

    public void setStage(Stage stage, Professor professor, FachadaProfessor fachadaProfessor) throws IOException, ClassNotFoundException {
        this.stage = stage;
        fachadaProfessor.recuperarTurmasProfessor(professor);
        this.professor = professor;
        this.fachadaProfessor = fachadaProfessor;
        this.turmas = FXCollections.observableArrayList(this.professor.getTurmasArrayList());
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        iniciarLayout();
    }
}

0

Você deve fazer log-in para responder a esta pergunta.

Pesquise outras perguntas com a tag .