3 Replies Latest reply on Nov 18, 2007 3:29 AM by pabera

    Update DataGrid over ArrayCollection

    pabera
      Hey,

      I have got a problem with the updating capabiliy of the ArrayCollection.
      I fill the array like this.

      quote:

      [Bindable]
      private var content:ArrayCollection = new ArrayCollection();
      private function contentRPCResult(event:ResultEvent):void {
      content = event.result.allEntries.entry;
      }


      The data I like to fill the ArrayCollection with, is information I got from a mysql database over PHP. It needs to be reloaded from time to time, because the content changes quiet frequently. So I used a "Refresh" button. While clicking on it the RPC "contentRPC.send();" gets sent again. The command works fine, because the first time the database content loads into the app.
      If I click on the refresh button, nothing happens. I thought, if the content of an ArrayCollection changes, the content of its dataprovider changes as well?! I used an XMLListCOllection in another app, there it works. If I send the HTTPRquest again, the content changes if there were any changes since the last load.

      I even tried removeAll() or refresh() to empty the Array and fill it again with the new data. It doesn't work. Only the first loaded content is displayed in the data provider. If i reload the whole app, the content shows the actuall content (which is the first loaded content, indeed!).

      So my question is: I fill an ArrayCollection with "contentRPC.send();" (HTTPRequest) once. The dataprovider shows the content. When I user "contentRPC.send()" again and the new content is different to the old one, how could I refill the ArrayCollection with the new content (it should automatically change the content of the dataprovider)?

      Hopefully you understand my problem. I am actually German, so it was hard for me to explain, what I really intend to do!
      Thanks for any help.

      greets lindner
        • 1. Re: Update DataGrid over ArrayCollection
          chris.huston.t10 Level 3
          It sounds like a cache problem. There are a couple of things you can do to prevent caching. One is to append a unique value to your HTTPRequest, something like the current time or a random number.

          url="yourserver.php?unique=" + String(Date.parse(new Date()));

          A second thing you can do is to tell your php script not to cache the value. I use the following:

          <?php
          header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
          header('Cache-Control: no-store, no-cache, must-revalidate');
          header('Cache-Control: post-check=0, pre-check=0', FALSE);
          header('Pragma: no-cache');
          ...
          ?>

          I use both of these solutions together, though probably just the first solution will work.

          Vygo
          • 2. Update DataGrid over ArrayCollection
            pabera Level 1
            Hey Vygo,

            thank you for your answer. Unfurtunatly it is not a cache problem. I tried the unique thing, which sounds very meaningful. But the ArrayCollection still gets not refreshed, or reloaded. When I use the PHP Script on its own, it always shows the current content, using no cache at all. So I know the right content gets passed to the flex app, but the app does not use it!

            Any other suggestions, maybe there is a cache problem in flex?

            I just took a look in the older app where I used an XMLListCollection to fill the dataprovider.
            There the command to gill the XMLListCollection was "HTTPRequest_ID. lastResult.XML_node". Now I fill the ArrayCollection only with "content = event. result.allEntries.entry;". I can not use lastResult at this point. Might this be a problem? I an't believe there is no way to fill an ArrayCollection at runtime more than one time?!

            greetings lindner
            • 3. Re: Update DataGrid over ArrayCollection
              pabera Level 1
              Hey Vygo,

              after testing over two hours, I finally tried out your way. And it really works. But I really can't believe that this is the only way to go. Anyway, thanks for your help.

              Greetings
              lindner