Can TableView commit changes to generic fields like String or Integer without extra step with setOnEditCommit?
Currently I use such structure:
@FXML
TableColumn<User, String> _tableStateUsername;
@Override
public void initialize(URL location, ResourceBundle resources) {
_tableStateUsername.setCellFactory(TextFieldTableCell.<User, String>forTableColumn(new DefaultStringConverter()));
_tableStateUsername.setCellValueFactory(new PropertyValueFactory<User, String>("username"));
_tableStateUsername.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<User, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<User, String> event) {
event.getRowValue().setUsername(event.getNewValue());
}
});
and it works fine, but I feel that it can be simplified (without using SimpleString)
I tried binding Value factory to field but no luck:
_tableStateUsername.setCellValueFactory(cellData -> Bindings.select(cellData.getValue(), "username"));
Is there any way to make cell set NewValue to bound field automatically?