Writeback support in DataFX

Over the last months, we have been working very hard on DataFX 2.0. We will talk about DataFX during JavaOne 2013, but I didn't want to wait to briefly mention one of the new cool features of DataFX 2.0, which is the write-back support.

With DataFX 1, you can easily obtain (remote) data and populate JavaFX controls with that data. Data can come from a variety of sources, in different format. In DataFX 2.0, it is also possible to modify data locally, and request that this data and then sent back to the original source. This is achieved by using a WriteBackHandler.

Both ObjectDataProvider and ListDataProvider now implement WriteBackProvider. As a consequence, when the data is changed locally after it has been retrieved (from a database, REST server, file,...) a callback will be executed in order to change the data on the source of origin. The developer is still responsible for doing this, by registering a callback handler with the DataProvider implementation.

You can checkout the code at https://bitbucket.org/datafx/datafx or you can download DataFX from maven central (groupId: org.javafxdata, artifactId: datafx-core and datafx-samples).

The code snippet below is taken form the JDBCSample.java file in datafx-samples, and it shows how to enable write-back support for a simple case where the data is stored in a relational database

DataReader dr = new JdbcSource(dbURL, converter, "PERSON", "firstName", "lastName", "country");
ListDataProvider lodp = new ListDataProvider(dr);
ObservableList myList = FXCollections.observableArrayList();
lodp.setWriteBackHandler(new WriteBackHandler() {
    public WritableDataReader createDataSource(Person me) {
    String statement = "UPDATE PERSON SET lastName=\'" + me.getLastName() + "\' WHERE firstName=\'" + me.getFirstName() + "\'";
        JdbcSource dr = new JdbcSource(dbURL, statement, null);
        System.out.println("Writeback called with statement "+statement);
        return dr;


DataFX will keep track of changes to properties in the retrieved data, and it will call the WriteBackHandler in order to make that change persistent.


speaking We will provide more samples and tutorials later, and you are very welcome to join us at JavaOne (CON3202, Wednesday Sep 25, 08:30 am, Hilton - Plaza B)

written on 03 Sep 2013 10:21.

no comments

Create comment