Over a million developers have joined DZone.

Writeback Support in DataFX

DZone's Guide to

Writeback Support in DataFX

· Java Zone ·
Free Resource

Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.

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.

speakingWe 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)

Connect any Java based application to your SaaS data.  Over 100+ Java-based data source connectors.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}