I have an List ObservableList<XYChart.Data<Number, Number>>
. I want to compute the average value of XValueProprerty for all Data contained into the list :
Without FXBinding :
See full code hereAs you can see, it doesn't work :/
The binding is invalid only when the list changes, so when the XValue of a Data changes, nothing append.
I have to register every XValueProperty()
into the bind()
method :
Now it works for all Data that was into the list at the beginning, but not for all added (or removed) Data after the init of the Binding
Let's make it work :
See full code hereWhile the complexity of your model is growing, you will have to register many listeners and the code is going to be less readable, less maintainable and less bug proof.
With FXBinding
Now let's replace our DoubleBinding by a magical FXDoubleBinding, it's 4 time step :
- Replace
new DoubleBinding()
bynew FXDoubleBinding()
- Change the method name from
computeValue()
tocompute()
- Remove
{bind(...)}
and replace it by theconfigure()
method - In the
configure()
method calladdObservable()
instead ofbind()
Every time the binding is becoming invalid, we will reconfigure it, so it's always a cool binding.
We will never have to add a listener even in a very complex model
An other example :
See full code here