Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Datagrid Not Populating

Avatar

Level 2
Hello,



Does anyone know why my datagrid is not populating? It runs
with no error, but no data is coming up.



Thanks,

Jimmy



Here's the code to the not working version



<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"

layout="vertical">



<mx:Script>

<![CDATA[

import mx.rpc.events.ResultEvent;

import mx.collections.ArrayCollection;



[Bindable]

private var myData:ArrayCollection;



private function resultHandler(event:ResultEvent):void{

myData = event.result as ArrayCollection;

}

]]>

</mx:Script>



<mx:WebService id="myService"

wsdl="
http://www.hawaiihotels.com/WSTest/Inventory.cfc?wsdl"

load="myService.getInventory();"

result="resultHandler(event)"/>



<mx:DataGrid dataProvider="{myData}"/>

</mx:Application>

3 Replies

Avatar

Level 3
Hi Jimmy,



Your event.result contains an Array. The 'as' operator
attempts to cast to the type you've specified (ArrayCollection) and
if it can't returns null. So your app was binding null to the
grid's dataProvider property. You could either do:



myData = new ArrayCollection(event.result as Array);



or change myData to type Array and do:



myData = event.result as Array;



Best,

Seth

Avatar

Level 3
I thought it was suppose to be



myData = event.lastResult;



is this only for java stuff?

Avatar

Level 3
The list-based classes (including DataGrid) do some massaging
in the setter for dataProvider. If the assigned value is an Array
it is wrapped automatically in an ArrayCollection. If it's already
a ListCollectionView (ArrayCollection or XMLListCollection) it's
used as is.



If the server returns data that's unpacked as an Array or
ArrayCollection either would be directly assignable to the
dataProvider property so a direct binding expression to a
WebService operation's lastResult would just work. However, if
having the local variable is useful it needs to be the proper type
to store the result.



Best,

Seth