I have a program that saves person details. Examples – first name, last name, MRN, dob, address, and preferred name. Each of these are textfields that a user can update. I’m trying to figure out how to have these save on the fly. As in once a user types in this fields, its being saved up to the database and can be seen in the program right away.
I have tried to accomplish this task in multiple different ways. I have several println statements within each function to try and capture and ensure information is being seen and saved. Also the MRN field is essentially another unique ID field.
I have first tried to use the setOnAction function tied to the textfield.
preferredNameTextField.setOnAction(e -> {
IPatientModel person= personService.findByMrn(mrnTextfield.getText());
System.out.println(personService.findByMrn(mrnTextfield.getText()));
person.setPreferredFirstName(preferredNameTextField.getText());
personService.save(person);
System.out.println(personService.save(patient));
});
This honestly didn’t do anything. Didn’t result in an error but also didn’t save the update. The println statement also didn’t capture any data.
I then used thought about using a listener and would see if a change was made to the field it would then update the person information.
preferredNameTextField.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if(newValue){
IPersonModel person = personService.findByMrn(mrnTextfield.getText());
System.out.println(personService.findByMrn(mrnTextfield.getText()));
person.setPreferredFirstName(preferredNameTextField.getText());
personService.save(patient);
System.out.println(personService.save(patient));
}else {
}
}
});
So the println did show that the Person table and that specific person update go through but it wasn’t saving. which i dont quite understand how thats possible. I would relaunch the program, go to that person and the perrferedNameTextfield would be blank.
preferredNameTextField.textProperty().addListener((obs, oldText, newText) -> {
if(newText != null || newText == null){
IPersonModel person = personService.findByMrn(mrnTextfield.getText());
System.out.println(personService.findByMrn(mrnTextfield.getText()));
person.setPreferredFirstName(preferredNameTextField.getText());
personService.save(person);
System.out.println(personService.save(patient));
}
});
So this resulted in the same as the previous. The data was opening in the println but when the program was relaunched it didn’t save, also querying the Person table showed it didn’t update successfully.
Is there a better way to be handling