Expand my Community achievements bar.

Nested data display from a WebService

Avatar

Former Community Member
Hi,



I publish a WebService using Apache CXF backing a Java App.
This Java application simply serves an array of Person objects:



Person{ id:int, name:String, nationality:Nation }

Nation{ id:int, name:String }



I am trying to list all person records using a DataGrid.
Below is the mxml file. (ws is the WebService variable)



<mx:DataGrid dataProvider="{ws.getProjects.lastResult}"
/>



id and name fields are all well displayed. But nationality is
just "object Object" which makes no sense.



I googled and found some solutions but could not make them
worked. One of the examples were using labelFunction. I tried it
like this:



// script starts here ..

private function lblFunc(item:Object,
column:DataGridColumn):String {

var sLabel:String = "n/a";

var sHeaderText:String = column.headerText;



switch(sHeaderText) {

case "nationality" : sLabel = item.name; break;

default:

sLabel = item.toString();

}



return sLabel;

}



//... some code here

<mx:DataGrid dataProvider="{ws.getProjects.lastResult}"
labelFunction="lblFunc"/>

// some more..



Ok, this also did not worked.



Is there any one who knows how to show nested properties
provided by a web service ?



Thanks,



Selcuk Bozdag
2 Replies

Avatar

Level 1
you are nearly there you need to put the labelFunction on the
<mx:DataGridColumn labelFunction="" />



the way i get it to work is to define all the datagrid
columns full code



private function labelFunc( item:Object ,
column:DataGridColumn ):String

{



return item.nationality.name;

}





<mx:DataGrid
dataProvider="{ws.getProjects.lastResult}">



<mx:columns>

<mx:DataGridColumn headerText="Name"
dataField="name"/>

<mx:DataGridColumn headerText="National"
labelFunction="labelFunc"/>

</mx:columns>

</mx:DataGrid>

Avatar

Former Community Member
Thanks very much. Yes, it worked the same way as you told.
Furthermore, I use labelFunction attribute of DataGrid to handle
all items in one place which I feel more comfortable.



Selcuk Bozdag