1 person found this helpful
I have to question the need for making multiple calls at all, when you're saving a list of items. If you're using data services the way to do this typically is to send everything you're saving in a list (arraycollection etc), and processing that list on the server all at once. You're adding some overhead by making multiple calls and I'm not sure I see the added benefit performance wise.
If I understand what you are saying about the trace functions you had, the reason all of them would seem to execute and "finish" before the result is reached is because Flex is firing off all those requests at once and then it moves on to other tasks. The result (or fault) handlers only get executed after a reply has been recieved from the server for each request, which takes some amount of time. If Flex/Flash waited for those replies before moving on, everything would freeze up (even the browser's UI) because it's all single threaded, so they use an event based design.
Does that help at all?
The second paragraph you posted is definitely worthwhile - still figuring out some of the inner workings of Flex calls (not just RPC stuff) that I use as I am pretty new to flex.
I don't have the code with me at the moment, but I think I have to use separate calls to the save function. My situation is this (and I plan on updating with code on Monday if necessary):
I have a datagrid that is populated using a single RPC (which is loaded into an arrayCollection first then the datagrid). Changes are made to the datagrid through a copy/paste function that I made, but these changes are only reflected on the datagrid (i.e. not in the dataprovider). When the user hits "save", the selected line (selectedItem actually - i.e. not an index but the object itself) is passed to another class which contains a modified version of my "modify data" function (brings up a dialog after choosing a given line allowing editting/validation of certain fields regarding the selectedItem). This changed version of "modify data" is then called and immediately closed effectively saving this record (without allowing the user to alter fields - so they don't have to hit save twice).
With the copy/paste function, I make all of these changes en masse and then have a loop that goes something like
for each (_object:Object in myDatagrid.selectedItems)
which ideally loops through the data and saves each item that has been changed. If there is a way to save all of the data in the datagrid simultaneously, I would appreciate a bit of help there (perhaps dealing with the bindings - right now I have the object I save as the destination and the source is myDatagrid.selectedIndex.[field name]).
Good to know about the other stuff, though - my understanding was a little bit lacking before
FYI - I am using weborb for Flex (www.themidnightcoders.com) and the save function in the ActiveRecords api is just for a specific active record (i.e. a row in the datagrid). I was essentially trying to develop a saveAll method that simply invokes this multiple times (though there may be a saveAll function in a different area that I am unaware of).
I've just finished based on your suggestion about using the array collection! I am still traversing it and calling the save function for an effective "save all" but desired to save only the dirty rows. This did add some unnecessary complications so I appreciate the solution (while I hang my head in shame for having not done this myself -_-)