views:

702

answers:

3

Hi Guys,

I've got a Flex 3 application with an HTTPService returning an Atom feed. I catch the result from it and store it in an arrayCollection which is then the provider of my Datagrid. I have no problem accessing the data from the "first-level" of my Array, but cannot go under it. Not very clear, so here is some code:

My XML [part of it]:

<entry>
<title>Test 2</title>
<id>http://collaboration.*****.com/collaboration/messaging/feeds/****/todo//7D6637D3E86B3ED3C12575B***8479&lt;/id&gt;
<link rel="alternate" href="notes:///C12575B4004***8/0/7D6637D3E86B3ED3C12575B6004E8479" type="application/vnd.lotus-notes"/>
<published>2009-05-14T16:17:37+02:00</published>
<updated>2009-05-14T16:17:56+02:00</updated>
<clb:todo>
<clb:uid>7D66***3ED3C12575B6004E8479</clb:uid>
<clb:due>2009-05-31T12:01:00+02:00</clb:due>
<clb:status>Not Started</clb:status>
</clb:todo>
</entry>

My Datagrid Code:

  <mx:AdvancedDataGrid y="10" id="notesGrid" width="90%" height="243" designViewDataType="flat" x="10" selectionMode="multipleRows" dataProvider="{notesArray}" >
   <mx:columns>
    <mx:AdvancedDataGridColumn 
     headerText="TITRE" 
     dataField="title" 
     fontWeight="bold"
     />
    <mx:AdvancedDataGridColumn headerText="STATUT" dataField="todo.status"/>
   </mx:columns>
  </mx:AdvancedDataGrid>

The "title" column shows the data correctly, but the status column is empty ! When I launch my app in debug mode, I can see that my notesArray has the correct format and I can access todo -> status with the value...

I've been stuck on this for a few days, I'd appreciate any help ! Thanks and best regards !!

A: 

This could have something to do with the fact that the "status" node is using a different namespace "clb" than your title. You may need to specify the namespace in order to access it's data.

I had to do something similar when retrieving XML data from a .NET WebService. It took me a few days to figure it out.

If your XML looks like this:

<?xml version="1.0" encoding="utf-8"?>
<atomFeed xmlns:clb="CLB.data">
    <entry>
    <title>Test 2</title>
    <id>http://collaboration.*****.com/collaboration/messaging/feeds/****/todo//7D6637D3E86B3ED3C12575B***8479&lt;/id&gt;
    <link rel="alternate" href="notes:///C12575B4004***8/0/7D6637D3E86B3ED3C12575B6004E8479" type="application/vnd.lotus-notes"/>
    <published>2009-05-14T16:17:37+02:00</published>
    <updated>2009-05-14T16:17:56+02:00</updated>
    <clb:todo>
    <clb:uid>7D66***3ED3C12575B6004E8479</clb:uid>
    <clb:due>2009-05-31T12:01:00+02:00</clb:due>
    <clb:status>Not Started</clb:status>
    </clb:todo>
    </entry>
</atomFeed>

Add this to the ActionScript where you handle the HTTPService result:

private namespace clbNS = "CLB.data";

use namespace clbNS;

For example:

package { import mx.rpc.events.ResultEvent;

public class handleAtomFeed
{
    private namespace clbNS = "CLB.data";

    use namespace clbNS;

    private function resultHandler(event:ResultEvent):void
    {
        // pares the XML and build your ArrayCollection
    }
}

}

Give it shot, it just might work!!!

Eric Belair
Hi Ben, Thanks for the tip. Unfortunately I've already tried using the namespace in the application, but it still didn't work.And the namespace is now cleared automatically when I put it in my ArrayCollection...The problem is only in the datagrid... When I do an Alert.show(notesArray[1].todo.status) in my AS, I get an alert with the correct value ! So wired :S
Florian
A: 

I'm pretty certain that the dataField property of DataGridColumn / AdvancedDataGridColumn doesn't automatically resolve nested properties, i.e. "todo.status"; you may want to try writing a labelFunction that will access the nested XML element for you.

cliff.meyers
A: 

A general rule I follow when it comes to problems of this sort is to do something like this (just to make sure that you are getting everything you are looking for):

import flash.utils.getQualifiedClassName;

// As a general rule, I don't find it the best idea to access an object in 
// an IList (ArrayCollection, XMLListCollection, et al ) by a dynamic property.
// Especially when they are coming from XML, the best way to access everything 
// is through getItemAt.
var len:int = todo.length;
for( var i:int = 0; i < len; i++ )
{
    var item:* = todo.getItemAt( i );
    trace( item, getQualifiedClassName( item ) );
}

After that, my first try would be replace this:

<mx:AdvancedDataGridColumn headerText="STATUT" dataField="todo.status"/>

with this:

<mx:AdvancedDataGridColumn headerText="STATUT" dataField="{ todo.status }"/>

Very often Flex does not play well with nested properties at all, but when you use the brackets, it gives the value which is found at that location as a more direct reference.

I think you are also better off using an XMLListCollection over an ArrayCollection. That way you can call children by name instead of relying on their normal index in the IList.

Christopher W. Allen-Poole