Consider the following usecase. You have an ObjectProperty of type Image and want to bind some values to its width and height.
For example, you could do it using select methods:
protected DoubleBinding photoWidth = Bindings.selectDouble(photo, "width");
Unfortunately, when image is null there is the following unpleasant stacktrace in the output.
To avoid it it would be great to provide default value to be returned if any of the selection steps return null. In JavaFX 1.3 days this used to work with default 0 value for numeric bindings, exceptions where never shown for such cases. For
example, this could be written as following:
protected DoubleBinding photoWidth = Bindings.selectDouble(photo, 0, "width"); // where 0 is the default value
WARNING: com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue Property 'width' in ObjectProperty [value: null] is null
java.lang.NullPointerException
at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.getObservableValue(SelectBinding.java:435)
at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.access$200(SelectBinding.java:384)
at com.sun.javafx.binding.SelectBinding$AsDouble.computeValue(SelectBinding.java:175)
at javafx.beans.binding.DoubleBinding.get(DoubleBinding.java:202)
at javafx.beans.binding.DoubleExpression.getValue(DoubleExpression.java:68)
at javafx.beans.binding.DoubleBinding.getValue(DoubleBinding.java:111)
at com.sun.javafx.binding.ExpressionHelper.addListener(ExpressionHelper.java:52)
at javafx.beans.binding.DoubleBinding.addListener(DoubleBinding.java:121)
at javafx.beans.binding.DoubleBinding.bind(DoubleBinding.java:152)
at javafx.beans.binding.Bindings$24.<init>(Bindings.java:1805)
at javafx.beans.binding.Bindings.divide(Bindings.java:1803)
at javafx.beans.binding.Bindings.divide(Bindings.java:2034)
at javafx.beans.binding.DoubleExpression.divide(DoubleExpression.java:217)
For example, you could do it using select methods:
protected DoubleBinding photoWidth = Bindings.selectDouble(photo, "width");
Unfortunately, when image is null there is the following unpleasant stacktrace in the output.
To avoid it it would be great to provide default value to be returned if any of the selection steps return null. In JavaFX 1.3 days this used to work with default 0 value for numeric bindings, exceptions where never shown for such cases. For
example, this could be written as following:
protected DoubleBinding photoWidth = Bindings.selectDouble(photo, 0, "width"); // where 0 is the default value
WARNING: com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue Property 'width' in ObjectProperty [value: null] is null
java.lang.NullPointerException
at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.getObservableValue(SelectBinding.java:435)
at com.sun.javafx.binding.SelectBinding$SelectBindingHelper.access$200(SelectBinding.java:384)
at com.sun.javafx.binding.SelectBinding$AsDouble.computeValue(SelectBinding.java:175)
at javafx.beans.binding.DoubleBinding.get(DoubleBinding.java:202)
at javafx.beans.binding.DoubleExpression.getValue(DoubleExpression.java:68)
at javafx.beans.binding.DoubleBinding.getValue(DoubleBinding.java:111)
at com.sun.javafx.binding.ExpressionHelper.addListener(ExpressionHelper.java:52)
at javafx.beans.binding.DoubleBinding.addListener(DoubleBinding.java:121)
at javafx.beans.binding.DoubleBinding.bind(DoubleBinding.java:152)
at javafx.beans.binding.Bindings$24.<init>(Bindings.java:1805)
at javafx.beans.binding.Bindings.divide(Bindings.java:1803)
at javafx.beans.binding.Bindings.divide(Bindings.java:2034)
at javafx.beans.binding.DoubleExpression.divide(DoubleExpression.java:217)
- relates to
-
JDK-8094059 BooleanProperty: longish info message bubbles up in application code
-
- Closed
-
-
JDK-8091544 Bindings.select*(): add new type-safe template based API instead of legacy-style set of methods
-
- Open
-
-
JDK-8096919 Bindings.select methods log superfluous warnings
-
- Closed
-
-
JDK-8091242 Bindings.select methods inefficiently implemented
-
- Open
-