JavaFx: not String null values and binding
Tom Schindl
tom.schindl at bestsolution.at
Wed Jun 10 12:15:07 UTC 2015
So if the value is null-able IntegerProperty is not the right type! You
need to use a ObjectProperty<Integer> but this is more of a user forum
question.
Tom
On 10.06.15 13:56, Александр Свиридов wrote:
>
> I have a POJO class Test that has Integer and String fields (all of them can be null). And I have javafx form with TextFields. To bind Test fields to text fields I use adapter. Now I create an instance of Test (all fields will be null)
> Test test=new Test();
> TestAdapter adapter=newTestAdapter(test);
> //the following line works, although String name=null
> nameTextField.textProperty().bindBidirectional(adapter.getNameProperty());
> //the following line throws exception Integer id=null
> idTextField.textProperty().bindBidirectional(adapter.getIdProperty(),newNumberStringConverter());
> This is the exception I get:
>> Exception in thread "JavaFX Application Thread" java.lang.NullPointerException at javafx.beans.property.adapter.JavaBeanIntegerProperty.lambda$get$38(JavaBeanIntegerProperty.java:95) at java.security.AccessController.doPrivileged(Native Method) at javafx.beans.property.adapter.JavaBeanIntegerProperty.get(JavaBeanIntegerProperty.java:92) at javafx.beans.binding.IntegerExpression.getValue(IntegerExpression.java:69) at javafx.beans.binding.IntegerExpression.getValue(IntegerExpression.java:44) at com.sun.javafx.binding.BidirectionalBinding.bind(BidirectionalBinding.java:88) at javafx.beans.binding.Bindings.bindBidirectional(Bindings.java:869) at javafx.beans.property.StringProperty.bindBidirectional(StringProperty.java:111)
> Everything works ok if I do this way
> test.setId(0);
> idTextField.textProperty().bindBidirectional(adapter.getIdProperty(),newNumberStringConverter());
> However, you can imagine how ugly this solution is - I loose all the abilities of null value and for my CRUD application it is death. Please, help me to understand how to work with Integer(and Others?) null values with bindings and adapters.
>
>
--
Thomas Schindl, CTO
BestSolution.at EDV Systemhaus GmbH
Eduard-Bodem-Gasse 5-7, A-6020 Innsbruck
http://www.bestsolution.at/
Reg. Nr. FN 222302s am Firmenbuchgericht Innsbruck
More information about the openjfx-dev
mailing list