8 Replies Latest reply on Jun 18, 2009 8:36 AM by Rob M Love

    Generated data and null values.

    Rob M Love Level 1

      In exploring Flex 4 (I will still call it that), how are null values handled on services. The setup is CF and FB4 and I have a table with only 2 required fields and the rest are not required. So why then in FB4 when I make the service call it throws this.

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at components.tractsMainView::addNewTractForm/createButton_clickHandler()[D:\Flash Builder 4\lmtools\src\components\tractsMainView\addNewTractForm.mxml:82]
      at components.tractsMainView::addNewTractForm/__button2_click()[D:\Flash Builder 4\lmtools\src\components\tractsMainView\addNewTractForm.mxml:174]

       

      It only works when I populate all data, and this is not the behavior that I am looking for. So how do I allow null values to pass to the generated code?

       

      What is the preferred method?

       

      Thanks,

      Rob

        • 1. Re: Generated data and null values.
          SunilAdobe Adobe Employee

          How are you invoking the service call?

          Was it generated by FB4 as part of Bind To Data or Generate Form?

          • 2. Re: Generated data and null values.
            Rob M Love Level 1

            I'm binding the inputs from the form (non generated form) and creating a new var of the data type, and passsing it to the service call (generated service call) to add new records.

             

            I played a little with the generated form, is there some info where I can read up on the how the bindings work with generated forms. there a little confusing like text="@{persons_data.b_day}".

             

            Thanks,

            Rob

            • 3. Re: Generated data and null values.
              SunilAdobe Adobe Employee

              The syntax is for 2 way binding, you can find more information on http://opensource.adobe.com/wiki/display/flexsdk/Two-way+Data+Binding

              Also, the problem I think you are getting is the values are null in the database and that gets assigned to the edit field / or that null is being referenced and it does not like that.

              you might want to add a small tweak in the setters generated that if it is null, then make it empty string.

               

              Hope this helps.

               

              Thanks

              -Sunil

              1 person found this helpful
              • 4. Re: Generated data and null values.
                Rob M Love Level 1

                Can you give or point me to an example of modifying the getters and setters that applys to this suitation?

                 

                Thanks,

                Rob

                • 5. Re: Generated data and null values.
                  SunilAdobe Adobe Employee

                  Based on your example

                  text="@{persons_data.b_day}

                   

                  I think you might be having a persons_data action script class.

                  If it was a generated class using the Service Wizard or Configure Return Type feature, then you will be having _Super_pesons_data.as file

                   

                  Just goto the file and change the setter for b_day if it is null then set it to a appropriate value in teh set b_day function.

                  1 person found this helpful
                  • 6. Re: Generated data and null values.
                    Rob M Love Level 1

                    Ok so lets take this a little further as I have already broke it trying to modify.

                     

                    Old setters:

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                    public function set survey_name(value:String) : void

                     

                    {

                     

                    var recalcValid:Boolean = false

                    ;

                     

                    if (value == null || _internal_survey_name == null

                    )

                    {

                    recalcValid =

                    true

                    ;

                    }

                     

                     

                    var

                    oldValue:String = _internal_survey_name;

                     

                    if

                    (oldValue !== value)

                    {

                    _internal_survey_name = value;

                    }

                     

                     

                    if (recalcValid && model_internal

                    ::_cacheInitialized_isValid)

                    {

                    model_internal::isValid_der = model_internal::calculateIsValid();

                    }

                    }

                     

                    public function set survey_no(value:Number) : void

                     

                    {

                     

                    var

                    oldValue:Number = _internal_survey_no;

                     

                    if

                    (oldValue !== value)

                     

                    New Setters:

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                    public function set survey_name(value:String) : void

                    {

                    var recalcValid:Boolean = false;

                    if (value == null || _internal_survey_name == null)

                    {

                    recalcValid = true;

                    }

                     

                    var oldValue:String = _internal_survey_name;

                    if (oldValue !== value)

                    {

                    if (value is null)

                    {

                    value = "";

                    }

                    _internal_survey_name = value;

                    }

                     

                    if (recalcValid && model_internal::_cacheInitialized_isValid)

                    {

                    model_internal::isValid_der = model_internal::calculateIsValid();

                    }

                    }

                    public function set survey_no(value:Number) : void

                    {

                    var oldValue:Number = _internal_survey_no;

                    if (oldValue !== value)

                    {

                    if (value is null)

                    {

                    value=0;

                    }

                    _internal_survey_no = value;

                    }

                    }

                     

                    It didn't like this.

                     

                    • 7. Re: Generated data and null values.
                      SunilAdobe Adobe Employee

                      ok, thanks for the info.

                       

                      1. it is better to override the setters in the actual entity class, as the Super_ class might get regenerated if there are any updates.

                      2. when you say it didn't like this

                       

                      Do you mean, it is still giving the same error?

                       

                      TypeError: Error #1009: Cannot access a property or method of a null object reference.
                      at components.tractsMainView::addNewTractForm/createButton_clickHandler()[D:\Flash Builder 4\lmtools\src\components\tractsMainView\addNewTractForm.mxml:82

                       

                      If so what is there at line 82 and what are you trying to access there?

                      • 8. Re: Generated data and null values.
                        Rob M Love Level 1

                        That was the issue, by modifying the version that doesn't get over written it worked fine.

                         

                        Oh and the weird thing is thee is nothing on line 82.

                         

                        Thanks for all the help.