Over a million developers have joined DZone.
Platinum Partner

Real World JavaFX with GraniteDS : the ACI Ticketing and Booking System

· Integration Zone

The Integration Zone is brought to you in partnership with Red Hat. Download the IDC Report: The Business Value of Red Hat Integration Products to learn more about Red hat Integration.

We are a company based in Italy building custom applications for companies and public institutions.

We have recently been hired for a project consisting in a booking and sales system for a company organizing boat tours in Venice: Aci Venezia Tourist (www.acivenice.it).

The system had to be reliable and fast to help agents handle large flows of tourists, implement business features such as bookings for agencies and groups, fast emission of tickets for boarding or management control and provide administrative features such as statistics, management and security.

Why JavaFX ?

Given these requirements, it was necessary to develop a system that would allow very quick and responsive interactions with the user. In addition we had to interface with thermal printers, so it was clear that only a desktop application could fit.

After analyzing various options, JavaFX emerged as a technologically innovative choice, due to its portability, a good number of native and third party widgets and a good MVC pattern. The ability to produce executable and installable desktop applications also played an important role in this choice.

Why GraniteDS ?

At first, we had developed our own layer based on JAX-WS to manage client / server communication with our Spring/Hibernate backend. We quickly faced several issues, mostly due to the complexity of the data model, such as circular references, the (in)famous Hibernate lazy loading errors, or the necessity to handle threads manually on the client application to prevent remote calls from blocking the UI.

We eventually managed to make it work but were not very satisfied with the result. Furthermore, building and maintaining this communication layer required a lot of time and resources that we did not spend in the development of the application itself.

Some time later, looking for a better solution, we landed on the GraniteDS’s project home page and its list of features made it seem like a product specifically designed to solve all our problems! The support for JavaFX was still in early beta at that time but we decided to give it a try and replace our home made plumbing. Indeed, after a short time we had already developed some parts of the application with excellent results. The efforts devoted to the client / server communication layer were just a bad memory!

Technical insight of the application

ACI app uses a pure Java stack:

  • Server: Jetty 8, Spring 3.1, Spring Data JPA and Hibernate 4.1

  • Client: JavaFX 2.2, GraniteDS 3 and Spring 3.1

The client / server communication relies on the JMF encoding (Java Messaging Format), a compact binary format provided by GraniteDS 3. Server-side Spring beans are called through the GraniteDS layer.

While the Spring / Hibernate-based server stack is quite common, we have chosen an innovative JavaFX-based client architecture using the GraniteDS 3 / Spring 3.1 integration. This combination provides a complete MVC and data management framework with dependency injection: FXML controllers are Spring beans, and all JPA entities received from the server are managed by GraniteDS in a client-side entity manager.

We have also used JavaFX data binding extensively in all parts of the application, which makes very easy to synchronize the data model with the views.

Here is a short example of how to quickly build a sortable and filterable table view based on remote server data. First, the FXML view which uses a simple TableView control:

<TableView id="tabellaTemplate" fx:id="tabellaEmail"
	prefHeight="618.0" prefWidth="1019.0" AnchorPane.bottomAnchor="10.0"
	AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0"
		<TableColumn prefWidth="120.0" sortable="true" text="Data"
				<PropertyValueFactory property="dataInserimento" />
		<TableColumn prefWidth="380.0" sortable="true" text="Oggetto"
				<PropertyValueFactory property="oggetto" />
		<TableColumn prefWidth="350.0" sortable="true" text="Destinatario"
				<PropertyValueFactory property="nomeDestinatario" />
		<TableColumn prefWidth="120.0" sortable="true" text="Stato"
				<PropertyValueFactory property="stato" />
And the Spring controller bean which wires a GraniteDS PagedQuery component as data provider for the TableView and handles user search actions:

public class EmailUi implements Initializable {

    private TextField textRicerca;
    private DatePicker filtroDataInizio;

    private DatePicker filtroDataFine;

    private TableView<Email> tabellaEmail;

    private PagedQuery<Email, Map> emailCustom;

    private void cerca(ActionEvent event) {
        try {
            emailCustom.getFilter().put("dataInizio", filtroDataInizio.selectedDateProperty().get());
            emailCustom.getFilter().put("dataFine", filtroDataFine.selectedDateProperty().get());
            if (textRicerca.getText() != null && !textRicerca.getText().isEmpty()) {
                emailCustom.getFilter().put("titolo", textRicerca.getText());
            } else {
        } catch (Throwable e) {
    public void initialize(URL url, ResourceBundle rb) {
        emailCustom.getFilter().put("dataInizio", filtroDataInizio.selectedDateProperty().get());
        emailCustom.getFilter().put("dataFine", filtroDataFine.selectedDateProperty().get());
        emailCustom.setSortAdapter(new TableViewSortAdapter<Email>(tabellaEmail, Email.class));

Good and bad of JavaFX

JavaFX has been very enjoyable to work with and is a great tool for developing desktop applications. Being built in the Java SDK runtime makes it really friendly for Java developers, and easy to use and deploy. It has a decent number of available widgets including nice charting controls and allows for a clean MVC architecture. Building complex views is quite easy using the FXML markup language and the ability to use CSS styling has been very convenient.

During the development of our application, we unfortunately encountered several issues, notably memory leaks (in particular when using TableView and selection models) that forced us to introduce ugly workarounds in the code making it much less clean and readable, and we wasted a lot of time to identify the bugs.

Some very useful widgets were also missing such as a text field with suggestions, or even a calendar widget and we had to find third-party components which are not necessarily very reliable. It seems many of these issues will be addressed in JavaFX 8.

Good and bad of GraniteDS

GraniteDS has been very helpful to develop and structure our application and has almost entirely eliminated the need for handling network communication in our code.

We have particularly enjoyed some of its features which have saved us a lot of time:
  • automatic pagination working with many widgets (ListView, TableView, ChoiceBox) with incremental loading of data and caching. Just great!

  • automatic generation of client side JavaFX bindable entities from the JPA model

  • transparent lazy loading of remote data

  • dirty checking of changes made in client side entities

  • Spring integration, both on the server and on the client

Except some early bugs in the beta versions which are now fixed, we have not faced too many issues with GraniteDS. It just needs some time to become familiar with its many features and the documentation is sometimes a bit short. This initial effort is really worth it and you can build your application much faster and become very productive once you are more familiar with the framework.

Work in progress

We are currently working on a mobile version of the software that we chose to develop natively for Android. We eventually plan to use the Android integration offered by GraniteDS for this mobile application and benefit from the same powerful features.

Some real numbers, and conclusion…

The application has been in production since mid-June 2013.

So far 78,000 tickets have been issued for about 140,000 trips. The whole database has about 310,000 records.

"Aci Venezia Tourist", the end customer, is very satisfied with the software that is helping a lot to optimize the management of travels and therefore the costs.

The speed of operations, given by the combination of JavaFX and GraniteDS, allows users to operate smoothly and focus only on their work and not on the technical aspects.



Just some links to the frameworks used:

The Integration Zone is brought to you in partnership with Red Hat. Download the IDC Report: The Business Value of Red Hat Integration Products to learn more about Red hat Integration.


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

{{ parent.tldr }}

{{ parent.urlSource.name }}