3 Replies Latest reply on Nov 29, 2010 1:58 AM by Claudiu Ursica

    How to reflect data changes back to the external XML

    Sen Imagines

      Hi,

       

      In one of my application,

       

      I use data for (any of) my Flex component from an external XML (thru a HTTPService) request & a Java backend function provides the XML data.

      I bind the HTTPService result to XMLListCollection & I supply this data for the dataprovider for my component.

       

      So, if I make any data changes (by adding / creating new items ) in the component, it will be reflected in the XMLListCollection (resulting in adding / modifying new nodes)

       

      My Question is how to make these data changes reflect back in the external XML?

       

      - Sen

        • 1. Re: How to reflect data changes back to the external XML
          Claudiu Ursica Level 4

          Assuming you want them in the same xml that comes from the server you need to

          post data back to the server. Whenever your data updates, fire the HTTPservice

          again to post new data (the new XML). If the backend does not have support for

          this it needs to be created. It is up to you if you replace the whole XML in the

          backend or send the whole XML or just parts of it. Also if the save fails you

          need to take care of the data inconsistencies ....

           

          HTH,

          C

          • 2. Re: How to reflect data changes back to the external XML
            Sen Imagines Level 1

            So, I have to use two HTTPService.

            One to provide the initial data - This should be binded to an XMLListCollection or ArrayCollection, then it has to be given as a dataProvider to the components and also this will get updated on making data(adding/updating) changes by the user

             

            Another, HTTPService which holds a copy of the updated XML which is to be updated back in the server end.

            • 3. Re: How to reflect data changes back to the external XML
              Claudiu Ursica Level 4

              Well not necessarily. While binding directly to the service in view is fast is

              also not very clean and reusable. Try to put your data inside model classes,

              view binds to those classes instead of the service. Also use a custom class to

              wrap your service and that gives you flexibility to change server properties or

              make 2 different calls with the same service. You need to write code yourself

              but in the end it will be easier to adjust changes. So when you load data you

              actually populate the model instead of bringing data straight to the view. This

              code usually gets executed inside a command class. So to be more specific:

               

               

              CustomService

              - var HTTPService

               

              function getData

              -- in here you have the service calling the get data method on the service

               

              function setData

              -- in here you have the service calling the save data on the server

               

               

              View

              var model:DataModel

               

              - controls binds to the model and display data from model

               

              - when click on save or whatever gesture you use for saving you dispatch an

              event with the new data.

               

              You  should use some MVC framework to do this for you..

              When event is dispatched the framework will create a command class instance and

              run it ...

               

              GetSaveCommand

              - var service:CustomService

               

              service.saveData(event.Data)

               

              service.getData()

               

              function result()

              function fault() - for the success or fault of the service call ...

               

              you can perform additional data transformation here id needed or employ the use

              of other class to do that if necessary ...

               

              Hope this makes sense. It is more work involved as you can see.

               

              Or you can go with 2 HTTPService instance in the view ...

               

              C