There are a couple of things that you can do that come to mind:
1. Set up explicit binding for your display - this will automatically
get the data when it arrives. you can do this either inline in the mxml
with {} or using a mx:Binding tag.
2. Utilize the dataChange event for bound elements if you need to do
something custom - I typically use this for triggering functionality in
a custom renderer. For example when the data change event occurs, you
can have a component check a flag to see if it needs to initiate a state
change etc...
Darin Kohles, Application Developer
[EMAIL PROTECTED]
Digital Positions, Inc.
2289 Peachtree Road NE
Atlanta, GA 30309
404-351-8878 support phone
404-351-2366 main phone
404-351-4055 fax
http://www.d-p.com/
________________________________
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Bieder
Sent: Friday, May 25, 2007 10:27 AM
To: [email protected]
Subject: Re: [AFFUG Discuss] MVC, Object Instantiation/Population,
Asynchronous Calls
First off, I would like to thank everyone for their quick reply to
Justin's original post. J My name is Ian Bieder and I also work for
Nexteppe. I am also a Flex newbie plus I just graduated from GaTech a
few months ago. I am really excited about Developing in Flex and from
what I have seen so far Flex looks very promising. Based on the many
responses to Justin's original message, he has asked me to elaborate a
little more on how we have things setup and our problem.
We are using WebOrb to make remote calls to our .NET backend for our
app.
In Flex we are using an MVC design. We have a singleton controller
object that initiates most of the major UI changes, remote data calls,
and holds references to most of the model objects (note: this singleton
controller will be broken up as our app gets larger). For example, we
have a class called "UserProvider" that handles some remote object calls
and it is declared in the controller. We initiate remote methods by
calling things like aUserProvider.getAUser(userID). Once aUserProvider
receives data back it stores it in variable that is method specific and
for example we can access it in the controller by calling
aUserProvider.result. aUserProvider also will fire off and event once
it gets a result set back from the remote service so that the controller
knows that new data has been returned.
Our problem arises when we would like to make use of methods in
UserProvider for multiple things in the UI. The way we have things
setup now gets the job done but I am really unhappy with it and I
foresee it causing us problems in the future. For example, we have a
part of the UI where we would like to view a quick summary profile of a
user and another where we would like to edit the profile of a user. For
both UI operations we need to pull all of the information about a single
user (i.e. call aUserProvider.getAUser(userID)). This is sort of how we
have the code setup now in the controller (I renamed, omitted some stuff
like fault handling etc., and made some small changes to make my code
more understandable for this example):
Once the "view user profile summary" button is clicked this method gets
called in the controller:
public function beginSwitchToUserSummaryView(): void
{
summaryViewWaiting = true;
userProvider.getAUser(("user to get complete profile
from").userID);
}
Once the "edit user profile" button is clicked this method gets called
in the controller:
public function beginSwitchToUserEditView(): void {
editViewWaiting = true;
userProvider.getAUser(("user to get complete profile
from").userID);
}
Once a result set is returned from userProvider after calling
"getAUser()" an event is fired that the controller catches and then the
controller calls this method that starts the necessary UI changes:
public function aUserWasReturned(): void
{
if (summaryViewWaiting) {
switchToUserSummaryView(userProvider.result); //tells the UI to now
display the user in the summary view
summaryViewWaiting = false;
}
if (editViewWaiting) {
switchToUserEditView(userProvider.result);
//tells the UI to show the user in the edit view
editViewWaiting = false;
}
}
Is there an easier way to reuse the same remote object call (i.e.
getAUser()) for multiple UI operations? I hate using flags like this
and I am fairly sure it is going to cause problems as the app grows.
Also, is there some sort of other way that we should be trying to
implement a MVC approach (Yes, I know, very generic question J)? Again,
thanks for everyone's helpful suggestions so far.
UPDATE: Based on the responses so far it looks like I should be passing
some information with my remote call that describes what method is doing
the calling. That way I can pass that data back and handle the returned
data accordingly. Also, Scott Talsma suggested that I take a look at
Cairngorm, because it handles a lot of this ,and I will definitely be
doing so.
Thanks,
--
Ian
Nexteppe Automotive Automation
(877) 572-8892 support
www.nexteppe.com
---------- Forwarded message ----------
From: Justin Nichols <[EMAIL PROTECTED]>
Date: May 24, 2007 10:19 AM
Subject: [AFFUG Discuss] MVC, Object Instantiation/Population,
Asynchronous Calls
To: [email protected]
First off I'd like to introduce myself. My name is Justin Nichols and I
work for Nexteppe Business Solutions and we deal in car dealer data/web
services. We're working on a new system using Flex, WebORB, and a .NET
backend. We're running into a conceptual issue concerning the
asynchronous calls being made when retrieving remote data. We are new
to the Flex game so please forgive any ignorance I may show :)
Here's the basic problem and I have a feeling about what the solution
would be, but I wanted to ask:
1) We are setting up our system using MVC as best we can
2) We have written some .NET backend objects, and for this example let's
say we're needing to populate an ArrayCollection (flex-side) of User
objects.
3) We have our controller set to retrieve, using a RemoteObject call, an
ArrayCollection of User objects called userList.
4) The scenario we're in is the following:
a) We have a button on the screen that when clicked we want to get
the userList and then perform some action using the userList.
b) The button onclick event will send the necessary call to the
controller which will in turn make the call to the server and retrieve
the list.
c) Immediately after the call is made to populate the userList
variable, another statement is written that will perform some action on
the userList (say userList.getItemAt() or whatnot).
d) The issue at hand, is that because the call is asynchronous, the
userList may very well be null when the userList.getItemAt() gets
called.
Now from what I've read, we simply need to set up a custom event that
gets dispatched once the userList object has been filled. However, the
problem then arises when we might have two separate UI operations that
would utilize the same userList object population methodology, so my
main question is, would we need to write an event handler for the
population of the userList object for each UI operation (thus knowing
what operation I'm really wanting to do once the userList object is
filled)? Or is there some other best practice technique that I'm
missing here?
Also, is this an issue that frameworks such as Cairngorm can help with?
I really appreciate all the help in advance and again I hope I'm not
being too...noobish :)
Thanks,
--
Justin Nichols
Nexteppe Business Solutions
(877) 572-8892
[EMAIL PROTECTED]
-------------------------------------------------------------
To unsubscribe from this list, simply email the list with unsubscribe in
the subject line
For more info, see http://www.affug.com
Archive @ http://www.mail-archive.com/discussion%40affug.com/
List hosted by FusionLink <http://www.fusionlink.com>
-------------------------------------------------------------
-------------------------------------------------------------
To unsubscribe from this list, simply email the list with unsubscribe in the
subject line
For more info, see http://www.affug.com
Archive @ http://www.mail-archive.com/discussion%40affug.com/
List hosted by http://www.fusionlink.com
-------------------------------------------------------------