2 Replies Latest reply on Mar 21, 2008 4:15 AM by Selcuk_Bozdag

    Nested data display from a WebService

    Selcuk_Bozdag
      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
        • 1. Re: Nested data display from a WebService
          ssmithstone
          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>
          • 2. Re: Nested data display from a WebService
            Selcuk_Bozdag Level 1
            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