Thanks for your reply, I was having trouble figuring out a way to call the cancelEdit
method from my UI Class. Finally managed to do it. Here is the working code snippet:
col6.setCellFactory(new Callback<TableColumn<User, String>, TableCell<User, String>>() {
@Override
public TableCell<User, String> call(TableColumn<User, String> param) {
TextFieldTableCell<User, String>myEditableTableCell = new TextFieldTableCell<User, String>(new DefaultStringConverter()) {
@Override
public void commitEdit(String val) {
int index = this.getTableRow().getIndex();
User newUser = this.getTableView().getItems().get(index);
StringProperty oldval = newUser.fullNameProperty();
try {
newUser.setfullNameProperty(new SimpleStringProperty(val));
um.updateUser(newUser);
log.debug("View updated as DB updated");
super.commitEdit(val);
} catch (SQLException e) {
cancelEdit();
newUser.setfullNameProperty(oldval);
log.error("User update failed ");
}
}
};
return myEditableTableCell;
}
});