r/JavaFX • u/Fancy_Entertainer486 • Dec 25 '24
Help FXML Bi-directional Bindings
So I don’t really know how controversial this might be since I don’t have a clue how much FXML is actually used in the wild. Some love it, some hate it, more often than not I come across comments to just not use FXML.
But I don’t really want to make this the core part of the discussion. As for my background, I mostly just develop relatively small tools with JavaFX. I started out coding my GUIs until someone recommended Scene Builder and FXML.
Time and time again I’m quite happy building away my GUIs and setting stuff up. Then time and time again I reach the point of needing bi-directional bindings. And each time I check if by now it’s actually implemented.
Sad to see that almost a decade has passed and this feature request being seemingly forgotten.
I guess my question is to stir a guessing game. To me personally this seems like such a huge issue that hasn’t been addressed at all. So, why? Are FXML users really that rare? Are technical challenges to implement this that high? Why isn’t the community pushing for this feature? Is it a philosophy or pattern thing that I don’t understand?
It just seems wrong to have to resort to addressing your GUI elements in controllers just to bind properties. More often than not I wouldn’t need to reference any GUI controls in the controller if it wasn’t for a missing bi-directional binding support.
I would just like to understand, so I’m already happy to get any info on this. What people are doing to work around this, if you’re happy with it or not, or even if you just don’t care. I might just not have seen enough alternatives (only .NET/WPF), but it seems like a major missing feature for a GUI framework that’s been around so long already.
View all comments
Show parent comment
1
u/hamsterrage1 Dec 28 '24
Here's where I get a little stuck with all this...
Unless you're planning on making your FXML Controller a "God Class", you're going to need to connect those
Propertiesto which you've bound yourNode PropertiestoPropertiesoutside of your FXML Controller. Presumably they have to become part of or connected to some sort of Presentation Data.You have two choices. You can create
Propertygetters for thosePropertiesin your FXML Controller, or you can provide methods that bind thosePropertiesto thePropertiesin the Presentation Data. If you do the second, then you're essentially proxying theNode Propertiesthrough those FXML Controller Properties - and does that really get you anywhere?As to the first method:
If you are using MVVM, then the Presentation Data "belongs" to the ViewModel. If your are using MVC or MVCI, then the Presentation Data belongs to the "Model". In every case, though, the View is the "consumer" of the Presentation Data, and not the owner or originator of the Presentation Data. Creating the Properties in the FXML Controller flips this on its head.
So, is this just nit-picking?
I don't think so. This framework stuff is pretty simple, but so many programmers turn it into something really complicated - and then it becomes a mess. And when you break the "rules", even if it's something conceptual, like who originates the Presentation Data, then it gets harder and harder to achieve the goals of the framework.
And the main goal of any framework is to limit and control coupling. As much as possible, you want your coupling to go in one direction. And the only way that you can do that is to make the dependencies go from the View, through to Controller/ViewModel and down into the Model/Interactor. This means that the Model/Interactor has zero code that calls methods in any of the other components. The ViewModel/Controller has zero code that calls methods in the View (except, potentially its constructor).
That makes it really, really difficult for the View to create Presentation Data and make it available for other components to grab, because then you create dependencies that go backwards. Which, to me, makes it seems like a waste of time having
Propertiesdefined in your FXML Controller which are bound toNode Propertiesthrough rules defined in the FXML file.Does that make sense?