I'm having major troubles sending some data to another class file called ValuesSubmitted.java, but only from one method located in my main Controller.java.
My problem is that in all other areas of my Controller.java class I can successfully SET and GET values to/from my ValuesSubmitted.java class with no issues. ValuesSubmitted not does have a corresponding FXML element attached to it, as ValuesSubmitted was intended for a data source.
Please follow my code as my comments will explain in further detail.
@FXML
private void ResetPersonnel(){
//Instantiating ValuesSubmitted java class
ValuesSubmitted values = new ValuesSubmitted();
try (Connection connection = DriverManager.getConnection(CONNECTION_STRING)) {
//Fetching SQL DB - working as intended
final String queryTitle = "SELECT * FROM PERSONNEL WHERE TRUCK_TYPE = '" + values.getTypeOfTruck() + "' AND TRUCK_NUMBER = '"
+ values.getTruckNumber() + "' AND SHIFT_COLOR = '" + values.getShiftColor()+"';";
PreparedStatement statementTitle = connection.prepareStatement(queryTitle);
String resultTitle;
ResultSet resultSetTitle = statementTitle.executeQuery();
while (resultSetTitle.next()) {
// Each result
resultTitle = resultSetTitle.getString("TITLE") + " " + resultSetTitle.getString("LAST_NAME");
// THIS ADDS EACH ENTRY FOUND INTO OBSERVABLE "list" variable located in this Controller.java class.(this works.)
list.add(resultTitle);
// This is SUPPOSE to add each entry found into an observable list called "personnel" located in a single class file called ValuesSubmitted.java
// ValuesSubmitted doesn't have a FXML page for it. It was intended for a data storage with all my setters and getters.
values.setPersonnel(list);
}
// When I Sys-Out this line, it returns 0 upon this method being called.
System.out.println(values.getPersonnel().size());
// This is my ListView instance object with "list" being the variable of my observable list.
// This populates my List view container successfully with the observable list located in Controller.java
crewMembersList.setItems(list);
/*
My problem is that in all other areas of my Controller.java class I can successfully SET and GET values in my ValuesSubmitted.java class with no issues.
Again, ValuesSubmitted not does have a corresponding FXML element attached to it, as ValuesSubmitted was intended for a data source.
*/
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
This is another method located in Controller.java that successfully sets data to the ValuesSubmitted.java class.
@FXML
private void addCrewMember() {
//TODO FIX DUPLICATE ENTRIES WITH CASE SENSITIVITY
TextInputDialog addPersonnel = new TextInputDialog();
addPersonnel.setTitle("Personnel Names");
addPersonnel.setHeaderText("Enter personnel title then last name.");
addPersonnel.setContentText("ex. \"FF Smith\"");
Optional<String> result = addPersonnel.showAndWait();
if (result.isPresent() && !addPersonnel.getResult().isEmpty()) {
values.setPersonnelMembers(addPersonnel.getResult());
}
// This line validates that the entry above was indeed added to the list.
System.out.println(values.getPersonnel());
}