Java Reference
In-Depth Information
ListDataProvider<Question> ldp = ListDataProviderBuilder.create()
.dataReader(restSource)
.build();
Worker<ObservableList<Question>>retrieve = ldp.retrieve();
return retrieve.getValue();
}
public static void main(String[] args) {
launch(args);
}
}
The relevant part, the implementation of the
getObservableList
method, is very simple. We first construct a
JsonConverter
that will convert JSON objects named “item” to
Question
instances.
Next, we create a
RestSource
, and assign the converter to it. We also supply information on the REST endpoint.
We then create a
ListDataSource
that will use the
RestSource
and retrieve the data.
Calling the
ListDataSource.retrieve
method starts an asynchronous Service. Instead of waiting for the result,
we can immediately return the result object to our visual controls. The DataFX framework will update the result object
while it reads and parses incoming data. For large chunks of data, this is very useful, because this approach allows
developers to render parts of the data while other parts are still coming in or are still being processed.
■
at the time of writing, the DataFX 8 apis are not final. Developers are encouraged to visit
http://datafx.io
and check the documentation for the latest api documentation.
Note
JAX-RS
The release of Java Enterprise Edition 7 includes the release of JAX-RS 2.0. This specification not only defines how Java
developers can provide REST endpoints, but also how Java code can consume REST endpoints.
In the next example, we modify the
QuestionRetrievalService
of Listing 11-14 to use the JAX-RS API. This is
shown in Listing 11-19.
Listing 11-19.
Using JAX-RS for Retrieving Questions
package projavafx.jerseystackoverflow;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
public class QuestionRetrievalService extends Service<ObservableList<Question>> {
private String loc;
private String path;
private String search;
Search WWH ::
Custom Search