2 Replies Latest reply on Jul 14, 2008 8:55 AM by jonesf

    Binding and null values

    jonesf Level 1
      If I want to make use of the nice binding functionality provided by Flex. But I can't figure out a couple 'simple' little things.

      - My object has a non-required property of type Number and I want to bind it to a TextInput component. But when it is null (I call it "null" because it comes from a Java server app where the value is null, but in ActionScript, it's NaN), my TextInput field shows the actual text "NaN". I know what NaN is, but it just want just want the TextInput control to be blank to indicate null/NaN. This is wired to a Java app on the server where number objects are nullable.

      - Similar idea for a date property. When the DateInput component is blank, I want it to set my date property on my object to null. Instead it throws an exception saying that "" can't be coerced to a date type.

      I'm using BindingUtils.bindProperty, but I'm think I'm missing some basic binding concepts here. Any pointers?

      Thanks
        • 1. Re: Binding and null values
          SujitG Level 2
          Hi,

          You can try creating setters and getters for the properties. In the getter function you can check for the null/NaN and the return appropriate value.

          Hope this helps.
          • 2. Re: Binding and null values
            jonesf Level 1
            Ok, thanks for your quick reply. It was a late night last night, today I'm a little more clear-headed :)
            I guess I failed to mention that I have many objects/properties like this, so your solution would work, but would be a maintenance headache in my case. So I just copied the BindUtils.bindProperty source and modified it to the following. Seems to do the trick. Thanks again.