Review Java EE6 and JavaFX 1.3 – Part II, the front-end

Mark Bakker

Summary
In the first part of this review (the JavaEE6 back-end) I created a small application which is a JSON REST service to be used as back-end for a JavaFX front-end.
This second part of my review covers a small review of JavaFX, to see if it meats my requirements as front-end for my personal finance application (see previous post).

My conclusion for now is that JavaFX is an interesting new technology, I think it can be used for small applications or forms (think about internet adds). But for serious applications it is not ready yet.
I am really missing Datagrids, the way you have to deal with Session cookies for the Rest service is far to low level. I hope someone can point me to a place where I can find better solutions for those problems (if there are).

Requirements
The basic functional and technical requirements I described in my previous post, but the most important requirements for the front end are:

  • Have an tree data table (in Flex it is called an advanced datagrid) for visualizing an hierarchical data structure.
  • Be able to show adds in the front-end to be able to earn the costs of the hosting.

The back-end service
The service I used in this review is an simple service for which I have to logon via Basic Authentication an can get User information (username) via an Rest call.

The javaFX client
First I created a new FavaFX project and added some fields to the form.
pf_client1

After this I created some code to do the login action and show the username.  (FYI: I now that this is no good OO-design but for this small test it is the best way to show it.)

public class User {

    var sessionCookie: String;
    var username: String;
}
var user: User = User {};

public class Main {
    // <editor-fold defaultstate="collapsed" desc="Generated Code">

    var userJsonInput;
    var userParser = PullParser {
                documentType: PullParser.JSON;
                input: bind userJsonInput;
                onEvent: function (event: Event) { // parse the JSON user data and populate the user object
                    if (event.type == PullParser.END_VALUE) {
                        if (event.name == "username") {
                            user.username = event.text;
                        }
                    }
                }
            }

    //todo make this a function to add the headers! Make ik possible to logout/ relogin
    function buttonOnMouseClicked(event: javafx.scene.input.MouseEvent): Void {
        var httpHeader = HttpHeader.basicAuth(usernameTextbox.text, passwordTextbox.text);
        var sessionHeader = HttpHeader {
            name: "cookie"
            value: user.sessionCookie
        };

        def request: HttpRequest = HttpRequest {
            location: "http://localhost:8080/pfserver/services/private/account/show";
            headers: [ httpHeader,sessionHeader ]
            onInput: function(input: java.io.InputStream) {
                userJsonInput = input;
                userParser.parse();
                if(request.getResponseHeaderValue("set-cookie") != null){
                    user.sessionCookie = request.getResponseHeaderValue("set-cookie");
                }

           }
           onException: function(ex: java.lang.Exception) {
              println("onException - exception: {ex.getClass()} {ex.getMessage()}");
          }
        }
        request.start();

    }
}

The first thing you see is the PullParser, this parser is an parser for JSON data. I fetched the event of an new field an added this to a global value (ugly, I know :-)).
Using this was quite simple, but in my opinion to low level for big JSON data structures.
Getting the data is done with the HttpRequest, searching for this function did costs me 30 minutes because this is changed in each new version of JavaFX. First there was some async package for this, but now we only have the HttpRequest. Using the HttpRequest was not complex but this time again to complex for big applications, simple things as a cookieManager are missing, of course I can write one myself, but this type of things will cost me to much time if I compare it to Flex.

The first requirement, having a tree data table is also not met, even a simple data table does not exists for now.

Conclusion
I will not use the current version of Flex for my new front-end. It's to low level at the moment compared to Flex. It is slowly getting there if I compare it to previous releases but it still has a long way to go.

Comments (5)

  1. Karan Nangru - Reply

    June 1, 2010 at 7:50 am

    Your conclusion's comparing Flex with Flex. I suppose your not in favour of JavaFX as compared to Flex. Well same here.
    Ought to mention that there many components such as datagrids , trees, sf that are not there in FX. You'll have to load the usual swing component in FX for tress and stuff - which requires extensive swing + FX handling and would thus consume much more effort.....

  2. Kenneth - Reply

    June 1, 2010 at 8:52 am

    Thanks for pointing out what I've been worrying about JavaFX.
    After few weeks of evaluation I also conclude JavaFX is not ready
    to develop serious business application.

  3. zilti - Reply

    June 1, 2010 at 12:23 pm

    What about using Apache Pivot if you need complex GUI elements?

  4. William Antônio Siqueira - Reply

    June 1, 2010 at 7:08 pm

    Hello,

    For a table view, there's three solutions:

    1 - JFXtras TableView
    2 - Rakesh Menon Table View: http://rakeshmenonp.wordpress.com/2010/05/22/javafx-1-3-%E2%80%93-tableview/
    3 - Bind to a JTable, from Java Swing.

  5. Albert - Reply

    June 3, 2010 at 7:24 am

    It would be interesting to compare it with a jQuery/html solution. That might be even easier then javaFX/Flex... What do you think??

Add a Comment