Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought

Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Author Topic: Clarification on data-binding best practice for Flex/Flash  (Read 10146 times)
Courseware Beta
Posts: 2

View Profile Email
« on: October 18, 2007, 09:25:26 »

In the Best Practices document, the very last paragraph (p. 34) states: "Another Mediator has previously expressed interest in that particular Notification and responds by retrieving the Proxy, and setting the dataProvider property of its stewarded View Component to the result property of the Proxy."

Do I understand this right: Assume I have a DataGrid in my view component and an object in the Model that has an ArrayCollection object to represent the data.  The view mediator component can retrieve the proxy for the data and obtain the model's ArrayCollection and set the DataGrid's dataProvider property, thus directly binding the model's ArrayCollection to the view's DataGrid for display?

Is that what you meant in this paragraph?  Or should the View in this case actually have another ArrayCollection and when the View mediator receives notifications that the model's data has been updated the mediator should retrieve the contents of the model's ArrayCollection (via the proxy of course) and modify the contents of the view's ArrayCollection to match?

The big issue for me is if I make the DataGrid allow editing when I have directly bound the model's ArrayCollection to the view's dataProvider.  In this case, unless I take special care to intercept the item edits, the resultant change will be bound directly back to the model's ArrayCollection without invoking the methods exponsed by the model's proxy or using a command to do such.

(I guess my lack of OOD roots is showing, but I'm trying hard to catch on to this paradigm as fast as I can!)
Global Moderator
Hero Member
Posts: 2871

View Profile WWW Email
« Reply #1 on: October 18, 2007, 01:18:30 »


Your first interpretation of the statement was correct.

Generally, we want the edits made at the DataGrid (or any visual control) to automatically update the Model, and in turn have other parts of the View informed of such changes if necessary.

If this is not the case, then sure, clone the data (an interesting job depending upon how complex it is) and use a different ArrayCollection (or Array for that matter). Then capture the events that happen at the View and shuttle them back to a Proxy method via the Mediator and/or a Command. Then send Notifications that will be heard by all the interested Mediators so that their view components will be updated.

The reason for simply retrieving the reference from the Proxy and setting it as the dataProvider for the visual control can just be filed under 'playing well with other frameworks'.

That is to say, Flex provides a wonderful solution for updating the data and dependent visual controls when changes happen. The ArrayCollection and XMLListCollections simply do the right thing.

If you happen to be using PureMVC with Flex, it'd be silly to repeat all that effort by adding methods and Notifications in the Proxy that duplicate what Collections are providing. Especially when those classes are going to be compiled into your app anyway if you just use them to hold data.

Pages: [1]