Java Reference
In-Depth Information
The reason for this is that when doing so, the setter methods will be called by the JAXB.unmarshal method when
it creates an instance of the Question with some specific information. Now that we are using JavaFX Properties instead
of primitive types, this is required. The JAXB framework could easily assign the value of the XML Element “owner” to
the owner String field, but it cannot assign a value to a JavaFX Property object by default.
By using XmlAccessType.PROPERTY , the setOwner(String v) method will be called by the JAXB framework,
supplying the value of the XML Element to the setOwner method. The implementation of this method
ownerProperty.set(owner);
will then update the JavaFX Property that is subsequently being used by the TableColumn and the TableView .
The other important change in the Question implementation is that we added a method
String getTimestampString()
This method will return the timestamp in a human-readable format. You might have noticed in Listing 11-16 that
we set the CellValueFactory for the dateColumn to a PropertyValueFactory that points to “timestampString” rather
than “timeStamp”:
dateColumn.setCellValueFactory(new PropertyValueFactory<>("timestampString"));
The reason for this is that the getTimestamp() method returns a long, whereas we prefer to visualize
the timestamp in a more readable format. By adding a getTimestampString() method and pointing the
CellValueFactory to this method, the content of the cells in this column will be readable time indications.
The examples we have shown so far in this chapter demonstrate that the Java Platform, Standard Edition, already
contains a number of APIs that are very useful when accessing web services. We also showed how to use the JavaFX
Concurrent Framework, the ObservableList pattern, JavaFX Properties, and the PropertyValueFactory class to
enhance the flow between calling the web service and rendering the data in the JavaFX Controls.
Although there is no rocket science involved in the examples, additional requirements will make things more
complex, and more boilerplate code will be required. Fortunately, a number of initiatives have already popped up in
the JavaFX community, with the goal of making our lives easier.
Using External Libraries
All our examples so far did not require any additional external library. The Java 2 Platform, Standard Edition, and the
JavaFX Platform offer a great environment that can be used for accessing web services. In this section, we use two
external libraries and show how they make accessing web services easier.
DataFX
The DataFX library is described at http://datafx.io and it provides an end-to-end toolkit for retrieving, parsing,
massaging, populating, viewing, and rendering data. These data might be obtained using web services that
communicate with well-known protocols such as REST, SSE, or WebSockets, but can also be obtained from a local file
system, a database, or a number of other data sources. DataFX 2 was released in late 2013, and DataFX 8 is expected to
be released in September 2014.
DataFX 8 consists of a number of modules:
Cell Factories, providing a number of useful
CellFactories and hence reducing the
boilerplate code that is often required in projects
DataSources, providing a level of abstraction about the origin of the data, both regarding the
physical location (file, network resources) and the format (JSON, XML, JDBC, etc.)
DataFlow API, providing developers a convenient way to manage data across workflows, and
to use injection
 
Search WWH ::




Custom Search