I'm currently working on a number of projects that use JavaFX. One of the characteristics all those projects share, is the requirement to be able to communicate with an enterprise backend. That justifies the work I spend on RedFX and DataFX, two JavaFX libraries that deal with retrieving, rendering and synchronizing data.
The focus of RedFX is the communication between JavaFX Clients and Java EE servers. RedFX allows clients to share data with each other and with backend modules. The original code was based on JavaFX 1.3.1 and has been ported to JavaFX 2.0. A number of brave beta-testers are now working with the new code, and a public release will be available soon.
The DataFX project enables client developers to populate JavaFX controls with data coming from different sources, and to visualize this data in a convenient way without the need of writing lots of boilerplate code.
In this blog entry, I will quickly show how you can use the DataFX library
to retrieve and visualize XML data obtained via a REST call.
Today, many enterprise projects make their data available via REST calls.
The result of a REST call is often an XML document, containing lots of
information. Not all this information is relevant to the particular
JavaFX project. Retrieving the relevant parts and populating a TableView
with this information can become rather cumbersome.
For this reason, the DataFX project contains the
XMLDataSource class. Using this class, developers can populate
a TableView with the parts in the XML that they want, without having to
parse the XML manually.
I'm using the
XMLDataSource class myself in the Uitpas
project that LodgON and
ACA-IT Solutions are building
for Cultuurnet Vlaanderen.
The project contains a backend that (amongst other things) can be queried
to obtain information about cultural events. The JavaFX frontend should show
the events that are relevant to a given location, and operators should
get a list-view of these events.
Somewhat simplified, the XML that is returned from a back-end call looks
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<item title="Biljarten" cdbid="77f811ca-ac5d-40a4-9d73-80335b6288cd"/>
NetworkSource ns = new NetworkSource("http://192.168.130.115:8080/uitpas/rest/uitpas/cultureevent?from=2011-11-01&to=2011-11-15"); XMLDataSource dataSource = new XMLDataSource(ns,"event","item/@title","normalPrice", "discountPrice"); TableView tv = new TableView(); tv.setItems(dataSource); tv.getColumns().setAll(dataSource.getColumns());Rendering the TableView will show a table with 3 columns: the title, the normal price and the discounted price. Each event will be on a single row in the table.
The DataFX project contains another very useful part: convenient CellFactories. The Currency CellFactory can be used to render the normal price and the discount price.
I want to stress that there are a number of ways for having interactions between desktop clients and remote backends. There is no single solutions to all problems. Developers should be aware of this. I am convinced that both DataFX and RedFX can contribute to faster development of enterprise JavaFX applications, but we want to hear from developers what they think is missing, or why we should support different patterns.
written on 14 Nov 2011 10:50.Create comment