Expand my Community achievements bar.

SOLVED

DataService Fill Operation Completion

Avatar

Level 1
How can you determine exactly when a Flex DataService fill
operation has completed?



ex:



dsDataService.fill(arrayList, 'flex:hql', 'From
com.package.Object);

trace(arrayList.length); // <-- This returns 0



***



while(arrayList.length < 1) {} // <--- This never ends





The trace returns 0 but if I wait a second or two before
calling it it returns with the correct size of 30.

The arraylist will also successfully bind to a datagrid.



Can I do something with the AsyncToken that is returned from
the fill to know when the operation is completed?



Thanks for your help!

1 Accepted Solution

Avatar

Correct answer by
Former Community Member
AsyncToken is one way to go. Here's an example where an
AsyncToken is used. Note that inline functions are being used for
result and fault handing but you can break these to seperate
functions as well.



var fillToken:AsyncToken = dsDataService.fill(arrayList);

fillToken.addResponder(new AsyncResponder(

function (result:Object, token:Object=null):void

{

// Do something with the result

},

function (error:Object, token:Object=null):void

{

// Do something with the error

}));

View solution in original post

4 Replies

Avatar

Correct answer by
Former Community Member
AsyncToken is one way to go. Here's an example where an
AsyncToken is used. Note that inline functions are being used for
result and fault handing but you can break these to seperate
functions as well.



var fillToken:AsyncToken = dsDataService.fill(arrayList);

fillToken.addResponder(new AsyncResponder(

function (result:Object, token:Object=null):void

{

// Do something with the result

},

function (error:Object, token:Object=null):void

{

// Do something with the error

}));

Avatar

Former Community Member
Right, I'd much rather see people start out with normal AS3
functions to

simplify things until they get a handle (pun intended) on the
nature of async

programming.



import mx.rpc.events.FaultEvent;

import mx.rpc.events.ResultEvent;

import mx.rpc.AsyncResponder;





private function doFill():void

{

var token:AsyncToken = dsDataService.fill(arrayList);

var responder:AsyncResponder = new
AsyncResponder(handleResult, handleFault);

token.addResponder(responder);

}



private function handleResult(event:ResultEvent):void

{

trace("Result received. Length = " + arrayList.length);

// Handle result.

}



private function handleFault(event:FaultEvent):void

{

// Handle fault.

}







See
http://livedocs.adobe.com/flex/201/langref/mx/rpc/AsyncResponder.html
too.





Avatar

Former Community Member
I prefer inline functions for simple one/two liner
result/fault handling and break them into seperate functions when
the handling logic gets more complicated. People have different
styles and I don't think there's one right/easier way.

Avatar

Level 1
Mete & Peter,



Thanks for the quick response; just what I was looking for.



Andrew R
The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----