8

javafx properties are a great way to connect data-model to a javafx gui because their binding model implements a powerful notification-update mechanism.

Properties and bindings are not strictly gui-related, rather they're an extension to javabeans.

So one would like to use them in the application model classes without introducing a dependency on the package javafx.beans.property.StringProperty and in general from javafx.*.

In other words: (update)
I may need to split up the application into two modules.
One module should contain just classes that manipulate the data (the Model classes, MVC speaking).
A second module would contain all the graphical gui stuff, that is javafx.

If my data-classes use javafx binding, I would introduce an import javafx.beans.anything; (the best thing would be that bindings were part of java.* or javax.*, so i wouldn't reference a "gui library" into a core-data library). The fact that javafx will be included in stardard releases alleviate this prolbem, but it seems a tricky solution. Afterall I think I squint a web application that depends on some swing "utility" class.

Are there any options available?

I'm evaluating the effort required to create regular javabeans properties with listeneres and bridge them to fx properties.

AgostinoX
  • 7,477
  • 20
  • 77
  • 137
  • 1
    Can you clarify what do you mean by `using javafx properties without dependency on javafx.beans packages`? You either use them from that package or write your own ones. And latter option is not very useful given that JavaFX is a part of Java since 7u4. – Sergey Grinev Sep 14 '12 at 11:19
  • I've added an 'in other words'. – AgostinoX Sep 14 '12 at 15:22
  • 1
    Sergey just gave you the right hint. If you like to use properties and binding just use these in your models! It's all part of the JDK since 7u4, anyway. – pmoule Sep 17 '12 at 14:22
  • So my core data objects (that i would want to run on a webserver without any gui at all) will depend on javafx... – AgostinoX Sep 17 '12 at 14:40
  • I'm in the same situation as AgostinoX. I want a model module that my FX app can leverage, but I want the module to be FX-agnostic. Although my testing shows you can use FX properties on non-fx threads and could thus use them in other contexts, undoubtedly consumers will assume that because they're FX properties they' will only fire from the FX thread...not so! So it gives off false impressions. I think I'm going to create my own properties ala http://stackoverflow.com/questions/441240/javabeans-alternatives – kylejmcintyre Oct 17 '13 at 19:30
  • Did you find a satisfying answer? – Kiril Dec 09 '13 at 13:07

2 Answers2

1

Binding of JavaFX object to POJO (Plain Old Java Object) techinque may help you here.

See next set of tutorials: http://ugate.wordpress.com/2012/06/06/javafx-pojo-bindings/

In two words you can use next way to access POJO objects:

    Person person = new Person();
    PathProperty prop = new PathProperty(
        person, "address.streetName", String.class);
    Bindings.bindBidirectional(prop, myTextField.textProperty());
    prop.set("123 1st Street");
Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141
1

As Sergey said: the jfxtras library is a solution with the BeanPathAdapter API: https://github.com/JFXtras/jfxtras-labs/blob/2.2/src/main/java/jfxtras/labs/scene/control/BeanPathAdapter.java

There is an alternative if you use Granite Data Services: it has a class generator that you can customize to generate the javafx properties. It is a beautiful framework which focuses on server-side integration of javafx applications. http://java.dzone.com/articles/data-management-javafx-and

zenbeni
  • 7,019
  • 3
  • 29
  • 60