I'll omit the fact that the JFX plugin for NB 6.0M9 is more trouble than its worth (see previous blog entry). I wanted to try a very simple app that gets a JFX frontend with a JPA-powered backend.
First surprise: JFX does not support annotations
This is a really bizarre decision. Without annotations a whole class of really powerful Java functionality is unavailable to JFX, starting from JPA @Entity creation to @EJB dependency injection, etc.
So, I cannot take a JFX data class, e.g.:
class Person {
attribute id : Number;
attribute firstName: String;
attribute lastName: String;
}
and turn it into a JPA entity:
@Entity
class Person {
@Id
attribute id : Number;
attribute firstName: String;
attribute lastName: String;
}
This simply does not compile.
OK, then...I guess I have to define JPA entities as regular Java classes and bind them via JFX in the UI.
Second surprise: JFX does not seem to understand Java type-safe collections / generics
I created a simple Java class called Person with a static method to return two instances of it in a List
Then tried to display this in the UI via this simple JFX class:
Frame {
height: 120
width: 500
title: "SimpleTableDemo"
content: Table {
columns:
[TableColumn {
text: "First Name"
},
TableColumn {
text: "Last Name"
}]
cells: bind foreach (p in Person.getPersons())
[TableCell {
text:bind p.firstName
},
TableCell {
text:bind p.lastName
}]
}
visible: true
}
where Person.getPersons() has a simple signature of:
public static List<Person> getPersons()
Well, this does not work, we get a runtime exception:
Main.fx:25: No such attribute firstName in class java.util.List: should be
empty
Only if I change the signature to explicitly return a Person array, i.e.
public static Person[] getPersons()
did everything work.
Needless to say, I am somewhat underwhelmed. It's nice to have Flash-style effects and everything, but if I can't easily retrieve data from the DB, pass it to the UI, bind it/display it, etc. then the tool is not very useful for your regular, everyday corporate applications.
Follow up to my previous blog: it seems like there really are no constructors in JFX, none. Only "new" triggers (like DB insert triggers). So if you have an instance variable that positively, absolutely needs to be initialized upon object creation, it seems there is no way to accomplish this (at least none that I see from the JFX manual).
And since my DBA colleagues are not that keen on triggers (things get complicated when you have multiple of them on the same object, especially in terms of controlling their execution order) it would be interesting to see if JFX has similar issues once you created a complex class in it with multiple triggers added by different sources...
I think for now I will stop my JFX experimentations, this language has a LOT of potential, but it still lacking in many areas that stops it from real-life use IMHO, namely:
a) lack of usable development tools
b) not very smooth integration with the existing Java functionality (annotations, generics, who knows what else)
c) triggers instead of constructors or actions (sorry, I just don't like this language design approach, period)
I'll stick back to good old "it just works" Java and hope Sun will keep improving JFX to make it actually usable for regular applications. It has a lot of potential, that's true, but Java/Flex/Silverlight killer it is not, at least not yet.
On the positive side, I just read Sun hired one of the creators of GCJ to work with Chris Oliver on future development of the language, so it's good to see they are serious about investing some talented manpower into its futher evolution.

12 comments:
Yeah I think it's not ready for primetime yet. It doesn't even have a real compiler yet, it is still just interpreted. And no visual designer.
Given that, I'd guess it's at least 6 months to a year away from being ready.
I'm suprised they didn't use groovy, it has all the features you need, annotations, builders for declarative interface building etc. I think Sun is suffering from NIH syndrome when it comes to groovy.
From what I can see, and like most people I'm no JavaFX expert myself, shouldn't you define what "p" is in some way? (suppose, "p:Person in Person.getPersons()")
Just a guess..
Sun didn't invent JavaFX either. F3 came from an outside company they bought.
I admit, Groovy looks interesting, but once again without proper development tools, its worthless.
Who cares if a language is by design more productive than plain vanilla Java, when Java's much more mature tools (e.g. Matisse) more than make up for the difference in productivity.
I find this is a general problem in the open-source ecosystem...lack of focus on development tools. In reality, they are just as important as the underlying technology itself.
Microsoft has understood this a long time ago and unfortunately it seems Sun is still learning the same lesson.
The problem is your a programmer. JavaFX isn't meant to replace java.
It's a simple tool for the flash designers (not programmers) to build pretty guis because swing + java are too complicated for them.
Fine, but pretty GUIs still have to do something: retrieve something from DB, display it, edit it, save it back, call existing Java logic, etc, etc.
JFX after all is not a RIA tool (despite Sun's claims), it is for all purposes an extra layer on top of Swing. And Swing is mostly used in corporate development, doesn't need Flash-type UIs, just good old regular well-designed business UI.
In that case, just give the designer a crash course in Matisse and they will probably be just as productive.
The data centric code should not be called from the gui anyway. The should be defined in there own java classes just as they always were.
At the moment swing is mostly used in corporate development. This suns to be suns attempt to get back some of the desktop space, which is now possible again with the speed improvements in 1.5+.
Wouldn't JavaFX code perform faster then generated code (I've never used matisse)? Plus from what (little) I've played with JavaFX it can do alot of simple scripting etc that I doubt matisse can.
I've always liked swing, but I like to build guis programaticaly. This is a tool for converting the flash, vb, etc drag and drop crowd.
Who in earth needs flash-style effects without an editor for effects of flash-quality?
That and the facts presented by you hint at a truth, that states: "JavaFx is NOT useful"
-sj
You can do constructors (ok - better call it constructor like behaviour) in JavaFX. See http://orangevolt.blogspot.com/2007/05/javafx-and-constructors_11.html
But at the end i agree with your resume - JavaFX is not ready for prime time yet.
but some day ...
Personally, I was very excited about F3 when Chris Oliver showed off some preview demos on his blog.
I think Sun has really done him a big disfavor releasing his project with so many overblown expectations (Flash/Silverlight killer???), without any development tools to support it.
A better approach would have been to release it on dev.java.net without much fanfare, work on it for a year to get both the language and dev tools up to speed and then they could have announced it with all the necessary fanfare during the next JavaOne.
I am afraid many will attempt to try JFX, get discouraged and not come back, even after it finally fulfills its initial promise.
Pretty much exactly like Swing, which is still suffering from preconceptions left over from its early versions, even though nearly all of them have been fixed really well by now.
You should post a link to your article in the users mailing list for JFX, and let Chris have a chance of addressing your concerns.
It's still very early, I think the key to the success of the language will be the tools, not if it supports annotations and the like.
Post a Comment