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]
Print
Author Topic: data binding from valueObjects to MXML components, is it possible?  (Read 8093 times)
zzal
Newbie
*
Posts: 7


View Profile Email
« on: May 15, 2008, 07:43:02 »

Hi,

I'm relatively new with pureMVC, and I have decided to go for it for my next big project (since I'd like to code at the speed of thought... ;) ).

I have started my project over the AppSkeleton and EmployeeAdmin demos to help me fully understand all the mechanisms. I rapidly found that I should just re-re-read the Best practices and implementation article. Very nice work.

I have modified completely the LocaleProxy to better fit my needs and it blow me away: I now use the ResourceManager and localized properties files (with compiler arguments: "-locale= -resource-bundle-list=bundles.txt") and it's incredible! Every mxml component that shows localized text just change automatically when I switch the language. i don't fully understand it but it works!
Example:
<mx:Label text="{resourceManager.getString(ApplicationFacade.LOCALE,'LANGUAGE')}:"/>

(note that the string is concatenate with ':' and it still work)

I'm getting to the point here.

What I want to is, for example, bind the text of a mx:Label with one value of a valueObject, like:
<mx:Label text="{ApplicationFacade.getLoginProxy().fullName}"/>

And in my LoginProxy:

public function get welcomeName():String {
   return 'Some localized text ' + loginVO.name;
}

but it doesn't work at all. Even if the loginVO.name changes, the label never changes.
I have setup a notification call to do it, but i'd prefer use data binding for that.

Can I?
Is it a bad practice?


thanks!
And here's the code of my modified LocaleProxy from the AppSkeleton demo, just to sneak peak...
« Last Edit: May 15, 2008, 07:48:28 by zzal » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: May 15, 2008, 08:56:41 »

The tecnical reason the update isn't happening is your getter isn't [Bindable] and sending a ChangeEvent. That's purely a Flex thing.

But databinding from the Model to the View is not a good practice. With the MVC pattern, we're trying to separate the Model from the View, and have them communicate in a loosely coupled way. Databinding in the view component to a class in the model means that they are now tightly coupled. The view component cannot be reused without that model class.

This is why the mediators are used. They allow us to write view components that are portable. They listen for events on the view component, and for relevant notifications from the rest of the system. They take the data from the model and inject it into the view and vise versa.

The best use of databinding in a Flex app is for doing the 'internal wiring' of a view component that gives the 'black box' its behavior. Examine again how the EmployeeAdmin demo does databinding inside of its view components for things like turning on buttons only when there is a selection and filling an input form from the members of a local VO reference.

-=Cliff>
Logged
zzal
Newbie
*
Posts: 7


View Profile Email
« Reply #2 on: May 15, 2008, 09:51:26 »

I was just looking at EmployeeAdmin effectively. Thanks, I changed my setup and it works great.

The reason I removed the [Bindable] directive, is that I was getting a warning from the compiler that it wasn't suppose to be there and will not make it, or something.

I knew somehow that binding the model object to the view component was not a great thing to do. I should read the doc for a tenth time...  ::)

thanks for your precious time Cliff!

Oh, and about the documentation of best practices, I think I found a small issue. I was getting an error with the code on page 45 (english):
:
if ( loggedIn ) loginVO = new LoginVO( );I added a setter for loginVO property and everything came out great.

thanks again!
Logged
Pages: [1]
Print