7 Replies Latest reply on Jun 27, 2007 5:05 AM by Clark_Kent101

    Repeater with empty dataprovider

    karel_s
      I have this repeater with a dataprovider:

      <mx:FormItem width="278">
      <mx:Repeater id="documentenRepeater" dataProvider="{documenten}">
      <mx:Label text="{documentenRepeater.currentItem.documentnaam}"/>
      </mx:Repeater>
      </mx:FormItem>

      If the dataprovider is empty, i get this error:
      TypeError: Error #1009: Cannot access a property or method of a null object reference.

      What is the best way to solve this issue?
      Thanks a lot

      K
        • 1. Re: Repeater with empty dataprovider
          Clark_Kent101
          insert a short-hand if statement within the dataProvider curly braces to check to see if the data provider variable is null. So you could do:

          dataProvider="{(documenten != null)?documenten:''}"

          Hope that helps,

          - Tony
          • 2. Re: Repeater with empty dataprovider
            karel_s Level 1
            Hi Tony,

            dataProvider="{(documenten != null)?documenten:''}"
            generates an error. (expects an > )

            When i remove the double quotes before the last curly brace, still got an error (rightparen is unexpected)

            Any ideas?
            Thanks

            K

            • 3. Re: Repeater with empty dataprovider
              Clark_Kent101 Level 1
              The double quote you removed before the last curly brace isn't double quotes, its two single quotes. Try inserting the two single quotes instead of the double quote.
              • 4. Re: Repeater with empty dataprovider
                karel_s Level 1
                Yes!, no errors in this line anymore, but still the same old error:
                TypeError: Error #1009: Cannot access a property or method of a null object reference.

                I guess the repeater needs an array anyway. I thought if the dataprovider is empty, the repeater should repeat himself zero times.

                Is it possible to do something like this:

                if array not empty then
                <mx:formitem>
                ...
                ...
                </mx:Formitem>

                end if

                K


                • 5. Re: Repeater with empty dataprovider
                  Clark_Kent101 Level 1
                  If the dataProvider is an array and the array is null, you shouldn't get that error - even if the dataprovider of the repeater is set to nothing, you still shouldn't get that error - here is an example:

                  ----------

                  <mx:Script>
                  <![CDATA[

                  [Bindable]
                  private var dp:Array = [1, 2, 3, 4, 5, 6, 7, 8, 9];

                  private function init():void
                  {
                  dp = null;

                  trace(dp);
                  }

                  ]]>
                  </mx:Script>

                  <mx:Repeater dataProvider="{(dp != null)?dp:''}" id="rp">
                  <mx:Button height="49" width="50"
                  label="{String(rp.currentItem)}"
                  />

                  </mx:Repeater>

                  ---------

                  I dont get any errors. The error is probably coming up when you try access specific data from an array/array collection. The Label within the repeater tags is what might be causing the error, change it to:

                  <mx:Label text="{documentenRepeater.currentItem}"/>

                  To see what happens.
                  • 6. Re: Repeater with empty dataprovider
                    karel_s Level 1
                    Tony,
                    You are correct.
                    It is not he repeater going wrong, it's the event.result handler!

                    my hhtpservice result event handler is throwing the error.

                    documenten=event.result.Documenten.Document
                    When this returning xml is empty, the error is thrown

                    guess i have to look in that direction

                    Thanks!


                    • 7. Re: Repeater with empty dataprovider
                      Clark_Kent101 Level 1
                      Cool, no problem.