1 Reply Latest reply on Jan 19, 2009 5:44 PM by ntsiii

    Noobie trouble with data model/provider concept

    Marlene Level 1
      I think I am misunderstanding the use of data in Flex. I thought I understood a data model (in simplistic terms) to be a sort of storage place for data coming from or going to a server. I understand that a data model can be constructed in MXML or ActionScript class. First question. Is the actionscript class the same as a Value Object. If not, what is the difference.
      I understood a dataProvider to be the supplier of data for Flex List controls. If I am using a source XML file in a Model tag(<mx:Model source="someFile.xml" />) can this be the dataProvider. Most of the example I studied use HTTP Service calls to get Array or XML data. Are the results of those calls a data Model? I am hoping someone can get me turned around and thinking straight about this.
        • 1. Re: Noobie trouble with data model/provider concept
          ntsiii Level 3
          Ok. "model" is a general term that means simply a location and structure for data storage. It does not necessarily need to be related to server data flow, but often is.

          It can be "located" many places in an app, but needs to be accessible to the User Interface component that need to display it.

          Sometimes the data model is simply a variable in the instance scope of the component that does the display. this makes the data only available to that particular component.

          Sometimes the data model is an instance var on the main application. This makes it available to the entire application via the mx.core.Application.application reference

          Sometimes the data model is a property of a singleton class.

          A "ValueObject" is an AS class that has properties and methods that relate to some logical "item". (DTOs, DataTransferObjects typically are dumb, posessing only transport properties and no methods)

          A data model typically consists of a collection(ArrayCollection or XMLListCollection) of value objects. You can think of an XML node as a value object.

          Yes, "dataProvider" is the property of a list-based control that holds the reference to the data model.

          mx:Model is a specific Flex data type. It is bad. Avoid it whenever possible. I'll explain why later if you want.

          In place of mx:Model, use mx:XML. All the benefits, none of the failings.

          The result of an HTTPService call can be a data model, but DON'T use it that way. Instead, define a [Bindable] instance variable to hold the data, and use a result handler to put the data from the call result into that var.

          These are very general questions, I hope I have helped. But really, just start coding, a lot of this will be come clear as you do.