PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: Roustalski on March 27, 2009, 07:13:46

Title: View State
Post by: Roustalski on March 27, 2009, 07:13:46
I have a composite component with a data grid in it with a few columns.

There is a new requirement for the user to be able to save the sort and order of the columns through logins. Classic user preferences.

What is the best way of going about persisting the state of the view?

More specifically, would there be anything wrong with storing some objects with the datafield/headertext in the appropriate order, and then in a command, build the columns dynamically from this list, which is then fed to the view via mediator?

Is there a better way?

Title: Re: View State
Post by: puremvc on March 27, 2009, 07:53:55
Not a problem. Just as a form might send an event to its mediator saying it has domain data to send, a component with a grid could send an event saying the layout changed. Don't habve the mediator reach down into the component grabbing those props off the grid, though. That breaks the encapsulation of the component. Use a VO that the component populates with the values and the mediator grabs and hands off to a proxy for persistence. And visaversa, the proxy retrieves it, and sends it in a note to the mediator who sets it on the component. Internally you can apply those values by binding if you like, or by a method that does what you described, adding the columns to the grid.

Check the employee admin demo to see this happen with a user vo populatiing a form, etc. Check CodePeek and RSSReader which use DesktopCitizen to persist an AIR client's size and position info for some view state persistence juju.