从另一个控制器访问一个控制器的文本字段

时间:2015-04-15 13:05:07

标签: javafx

我想要设置值的第一个控制器:

public class NewProjectScreenController  implements Initializable,ControlledScreen {
   public String result;
    ScreensController myController;
    /**
     * Initializes the controller class.
     */



     @FXML
     public void goToProjectUpdateScreen(ActionEvent event) {
            myController.setScreen(MainController.screen6ID);
         Session session = NewHibernateUtil.opensession();
        session.beginTransaction();

       Query queryResult = session.createQuery("from Project where ProjectId = 3 and RegistrationId= 1");
  java.util.List allUsers;
  allUsers = queryResult.list();
  for (int i = 0; i < allUsers.size(); i++) {
   Project project = (Project) allUsers.get(i);
   //System.out.println("Database contents delivered..."+ project.getProjectname()); 
   result=project.getProjectname();

  ProjectCreationScreenController.setText(result);

  }

第二名管制员:

public class ProjectCreationScreenController implements Initializable,ControlledScreen {

    ScreensController myController;
    /**
     * Initializes the controller class.
     */


    @FXML
   private static TextField proname;
   public static void setText(String value) {
   proname.setText(value);
}  


    @FXML
    private TextField prodescription;

    @FXML
    private TextField OutputIntegration;

    @FXML
    private Button button;



     @FXML
       private void goBack(ActionEvent event) {
        myController.setScreen(MainController.screen5ID);
    }


        @FXML
       private void gotoSave(ActionEvent event) { 
           Project project = new Project();
        project.setProjectname (proname.getText());
        project.setProjectdescription(prodescription.getText());
       project.setOutputintegration(OutputIntegration.getText());
        Registration r= new Registration();
       r.setRegistrationid(3);
       project.setRegistration(r);
       ProjectModule.AddProject(project);
      // button.setDisable(false);
    }
    @Override
    public void initialize(URL url, ResourceBundle rb) {

    }    

    @Override
    public void setScreenParent(ScreensController screenParent) {
       myController=screenParent;
    }

}

实际上这里的问题是我从db获取值但问题是当我尝试在textfield中设置值时,它给出Null指针异常。

当我尝试调试它时,我能够从db中获取值,并且在setext函数中,它正在取精确值,但唯一的问题是在UI中设置值。

使用java fx和hsql

0 个答案:

没有答案