When I run this minimized example code and click t...
# tornadofx
d
When I run this minimized example code and click the button I get
java.lang.RuntimeException: A bound value cannot be set.
because
x2p
in ThingModel is two-way bound. Is there any way to change the
val x2p = bind(Thing::x2Property)
call to be just a one-way binding? I'm only using it for display purposes -- there's nothing that needs to be written back.
a
Maybe i dont get all the points but why dont you just use
x
directly in the view when its only for displaying the value x 2 ... Like
override val root = vbox { label(stringBinding(thing1.x){value *2})}
Or you could try something like this which worked for me //Model
val travelCosts: NumberBinding = Bindings.multiply(travelDistanceProperty, costsPerKilometerProperty)
//ItemViewModel
val travelCost = bind(Model::travelCosts)
d
This is simplified version of the code. The real code is doing more complex property manipulation and there's kind of a long binding chain leading to the last property -- that's why it can't be x directly in the view.
I think the problem with an integerBinding (or other binding) is that they appear to be lazily evaluated? With the code commented out on lines 9-15, I think there's nothing to force the x2 binding to evaluate. In the gui I see
IntegerBinding [invalid]
for the label. And then, with that code uncommented I see
IntegerBinding 2
which looks kind of weird. And I don't see the value in thing1 changing after the model commits.