4 Replies Latest reply on Sep 19, 2006 7:02 AM by JSSanders

    Passing Complex Object into Grid Component

    JSSanders
      OK here is what i am trying to do.

      I have a grid component, and I wanted to display on the grid, a list of ship objects. Think of this like a cruise liner.

      I am retrieving these objects from a java/hybernate/spring adapter using remote object, and it works ok. I get back an arrayCollection, then I build a new array, populatate it with Actionscript ship objects, which has an embedded port object.

      Ship has attributes like Name, id, comments etc. And it has an embedded homeport object also.

      The port, has name, country and comments too.

      I can get the object to come back, and its being built correctly. I have ship objects and each one has its own port object, I see in the debugger the objects and thier embedded objects and the embedded object values. So I know the constructor is working fine. Here is the problem.

      I set the dataprovider attribute to match the array of completed ships, and I can get the grid, to display all the ship data, but not the port data.

      So Here is my code:

      <mx:DataGrid id="ShipListDataGrid" width="978" height="190" dataProvider="{initDG}" creationComplete="loadAllShips()" selectedIndex="0" >
      <mx:columns>
      <mx:DataGridColumn headerText="Name" dataField="name"/>
      <mx:DataGridColumn headerText="Class" dataField="clazz"/>
      <mx:DataGridColumn headerText="Comments" dataField="comments"/>
      <mx:DataGridColumn headerText="Port Country" dataField="port.country" />
      </mx:columns>
      </mx:DataGrid>

      Now the colums name, clazz, comments all work perfectly, as they are attributes of ship. However, port.country does not work, it just shows a blank column, even though that is the correct notation to get to that data field, for the attribute of that ships port home country. Its just a string, so for the port called miami, the country is "USA". This does not display.

      However if I remove port.country, and only put in port, then it shows that whats in that column displays as Object : Port.

      So it seems that the grid knows theres an object in there. But not what to do with it?

      I have created a masterViewList and a masterDetails component, and the viewList is the grid, and the details is the details section of the ship. So there it shows a form, and the form shows all the details of the ship selected in the list above. Heres the interesting thing. using a label field, I can change the selected list item on the grid, and show the ship.port.country in a label on the bottom, so it can transverse the ship object, but just not seemingly in the grid.

      What can I do? Why does it work with a label field, and not in the grid? Why will the grid not show an embedded string attribute for an embedded object, but a label or text box will? What am I doing wrong?