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 [2]
Print
Author Topic: Flex databinding of VO's (model <> view) , good or bad?  (Read 22077 times)
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #15 on: February 22, 2010, 07:47:28 »

However, looking at the EmployeeAdmin demo I see that a new UserVO is created and sent back on Submit().  I was thinking that the approach described in this topic would eliminate the need to send VO's back and forth because we would be working with the same copy.  
If you revisit that application (actually run it and click an employee in the grid, populating the form, and then edit and submit your changes), you'll realize that you don't want to be editing the original VO. Otherwise, abandoning your changes would NOT be as simple as clicking Cancel instead of Submit.

Instead, we want to populate the form, edit it locally in the form without our changes disturbing the rest of the system, and send back a new one if we like our changes.

If you were working with the same object held in the Proxy, then as you modify your employee in the form every keystroke could cause your changes to be reflected in the data grid (if you were using two way binding (which we're not in this demo but often do - see my answer to your next question below).

What happens when you click cancel? Well, if you're editing the only known good copy, you have to have a backup copy to replace the edited copy you're abandoning. So either way, you're working with two copies. It's just that the latter way doesn't make sense because you don't want your changes making it out of the form until you've ok'd them.

I thought that the bindable communication was both ways. So that if I have this...

:
[Bindable] public var currentProject:ProjectVO = new ProjectVO;
<mx:TextInput id="pd_projectCode" text="{currentProject.projectCode}"/>

...it would mean that and changes to the pd_projectCode.text are also reflected on the currentProject.projectCode.  My view component has alot of fields so was trying to prevent having to get assign all the component values to my VO to be sent back to the proxy.
Nope. That's one way binding from the VO to the form. To get binding back from the form to the VO, you need to additionally use a binding tag that watches the changes on the form and updates the VO.

:
[Bindable] public var currentProject:ProjectVO = new ProjectVO;
...
<mx:Binding source="pd_projectCode.text" destination="currentProject"/>
<mx:TextInput id="pd_projectCode" text="{currentProject.projectCode}"/>

-=Cliff>
« Last Edit: February 22, 2010, 07:52:24 by puremvc » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #16 on: February 22, 2010, 07:55:10 »

Did some more research last night and I think what I need to do is as stated in this post.  http://forums.puremvc.org/index.php?topic=1365.0

By creating a custom view component that comes with its built in VO?
That thread (as far as I can tell) only talks about having a VO that can be repackaged into a library with a view component that uses it. I don't see that it changes anything with regard to how you deal with that VO in the application.

-=Cliff>
Logged
Pages: 1 [2]
Print