0 Replies Latest reply on Dec 9, 2007 3:10 AM by Constantin Ehrenstein

    Using Data Models and Repeater together

    Constantin Ehrenstein
      Hi there,

      in a contact database Flex frontend I want a person to possibly have zero, one or more addresses. So it seams reasonable to use a Repeater and to tie its dataProvider to an ArrayCollection. I then fetch the existing data from the database (in fact, I am using AIR and a SQLite database), assign the resultArray to the collection's source property and the form fields are repeated just like expected. I am running into difficulties whenever I actually add an address and -change- data.

      Imagine a contact person has no address in the db yet, and the user wants to add a business address and a private address. What would the user usually do?

      1. user clicks on an UIComponent (e.g. a Button labelled "add address"), a click event handler will create a new ArrayCollection item behind the scenes, thus also creating the corresponding fields via the Repeater.
      2. user fills in the data for the first address (in this example, the business address)
      3. user creates another set of fields via interaction with the UI
      4. user fills in the data for the second address (in this case, a private address)
      5. user submits the changes via some kind of interaction with the UI (e.g. a button "save changes")

      Now, if the dataProvider of the Repeater instance is set to the ArrayCollection instance "someCollection" and the text property of, say, the street field to {someRepeater.currentItem.street}, the existing data will show, but if the user has entered data for the first address and interacts with the UI to create a new set of form fields, all data for the first address will irreversably lost, since the properties of the ArrayCollection dataProvider cannot be bound due to their nature as Objects and the Repeater will rebuild the form fields with the (unbound) empty values of the first address.

      So, the solution to make the dataProvider properties bindable is to choose ObjectProxies or Model instead, and since there is no predefined class in Flex that means that you'll have to create a custom class implementing ICollectionView. Or have I missed something?

      So my question is: since it is quite common to combine repeaters with bindable properties, is there (or will there be) a way that Flex might support that combination out of the box?

      Best regards

      P.S.: EDIT: the ordered list feature of this forum doesn't seem to work.