May 18
I’ve asked this questions before, but this is a more elaborate view on it.
This is a burning question for me, because many of us have a data model already existing, particularly retrieved from some data source such as a database, XML files or binary formats, and now we want to leverage the power of JavaFX to impress our clients (and bosses).
There are a few issues here:
- How do I notify about a property change? Just by saying the words, I go back to think about the JavaBeans technology and about the PropertyChangedEvent and Listener.
- How do I get and set properties? Again, the JavaBeans standard comes to mind with the
getandsetmethod conventions we’ve come to know. - How do I create new Java objects? The easiest way would be to just have an empty constructor and allow for JSON-construction parameters to be passed using the
setter methods. The problem here is how to allow creation of objects using factories, when sometimes necessary (such as with the JAXB framework). - How do I effortlessly implement
binding andinversecapabilities in a regular Java class?
So we can have a few solutions to discuss:
- Using the JavaBeans’ architecture for plugging beans into JavaFX.
- Using only a set of the architecture, such as the
setandgetstandard (used by most binding frameworks like Hibernate, JAXB etc) and thePropertyChangeEventandPropertyChangeListenerconcepts and reimplement them, firing events as properties change. - Use some sort of aspect oriented programming concepts and attach our classes with annotations which would intercept changes to the properties and fire up the aforementioned events themselves.
- Or what?
I’ve taken the liberty of adding a new entry to the JFX Wiki (it is a Wiki after all…) about this subject. I expect you all to go there and give a voice to this problem, as without any pluggability to regular Java data models, JavaFX is really just a Flash competitor, and not a new UI framework for Java.
Liked Chaotic Java? It's free! But I also make some other things that aren't, which you might like. Like Firewall, a rule changing, turn based strategy game for iOS.