views:

372

answers:

2

Problem: Flex/Flash4 client (built with FlashBuilder4) displays the xml sent from the server exactly as is - the datagrid keeps the format of the xml. I need the datagrid to parse the input and place the data in the correct rows and columns of the datagrid.

flow: click on a date in the tree and it makes a server request for batch information in xml form. Using a CallResponder I then update the datagrid's dataProvider.

[code]

<fx:Script>
    <![CDATA[
        import mx.controls.Alert;
        [Bindable]public var selectedTreeNode:XML;
        public function taskTreeChanged(event:Event):void {
            selectedTreeNode=Tree(event.target).selectedItem as XML;
            var searchHubId:String = selectedTreeNode.@hub;
            var searchDate:String = selectedTreeNode.@lbl;
            if((searchHubId == "") || (searchDate == "")){
                return;
            }
        findShipmentBatches(searchDate,searchHubId);
        }
        protected function findShipmentBatches(searchDate:String, searchHubId:String):void{
            findShipmentBatchesResult.token = actWs.findShipmentBatches(searchDate, searchHubId);
        }
        protected function updateBatchDataGridDP():void{
        task_list_dg.dataProvider = findShipmentBatchesResult.lastResult;
    }
]]>
</fx:Script>
<fx:Declarations>
    <actws:ActWs id="actWs" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
    <s:CallResponder id="findShipmentBatchesResult" result="updateBatchDataGridDP()"/>
</fx:Declarations> 

<mx:AdvancedDataGrid id="task_list_dg" width="100%" height="95%" paddingLeft="0" paddingTop="0" paddingBottom="0">
    <mx:columns>
        <mx:AdvancedDataGridColumn headerText="Receiving date" dataField="rd"/>
        <mx:AdvancedDataGridColumn headerText="Msg type" dataField="mt"/>
        <mx:AdvancedDataGridColumn headerText="SSD" dataField="ssd"/>
        <mx:AdvancedDataGridColumn headerText="Shipping site" dataField="sss"/>
        <mx:AdvancedDataGridColumn headerText="File name" dataField="fn"/>
        <mx:AdvancedDataGridColumn headerText="Batch number" dataField="bn"/>
    </mx:columns>
</mx:AdvancedDataGrid>

//xml example from server
<batches>
    <batch>
        <rd>2010-04-23 16:31:00.0</rd>
        <mt>SC1REVISION01</mt>
        <ssd>2010-02-18 00:00:00.0</ssd>
        <sss>100000009</sss>
        <fn>Revision 1-DF-Ocean-SC1SUM-Quanta-PACT-EMEA-Scheduled Ship Date 20100218.csv</fn>
        <bn>10041</bn>
    </batch>
<batches>

[/code]

and the xml is pretty much displayed exactly as is shown in the example above in the datagrid columns...

I would appreciate your assistance.

A: 

I tried a simplified version of your sample using a simple xml literal, and it works fine for me..

here's what I've got

    <fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        protected function onCreationCompleteHandler(event:FlexEvent):void
        {
            task_list_dg.dataProvider = data..batch;
        }

        private var data:XML = //xml example from server
            <batches>
            <batch>
                <rd>2010-04-23 16:31:00.0</rd>
                <mt>SC1REVISION01</mt>
                <ssd>2010-02-18 00:00:00.0</ssd>
                <sss>100000009</sss>
                <fn>Revision 1-DF-Ocean-SC1SUM-Quanta-PACT-EMEA-Scheduled Ship Date 20100218.csv</fn>
                <bn>10041</bn>
            </batch>
            </batches>;



    ]]>
</fx:Script>

<mx:AdvancedDataGrid id="task_list_dg" width="100%" height="95%" paddingLeft="0" paddingTop="0" paddingBottom="0">
    <mx:columns>
        <mx:AdvancedDataGridColumn headerText="Receiving date" dataField="rd"/>
        <mx:AdvancedDataGridColumn headerText="Msg type" dataField="mt"/>
        <mx:AdvancedDataGridColumn headerText="SSD" dataField="ssd"/>
        <mx:AdvancedDataGridColumn headerText="Shipping site" dataField="sss"/>
        <mx:AdvancedDataGridColumn headerText="File name" dataField="fn"/>
        <mx:AdvancedDataGridColumn headerText="Batch number" dataField="bn"/>
    </mx:columns>
</mx:AdvancedDataGrid>

Are you sure your data is arriving in the format you're suggesting? (check the Data/Services tab in FB)

What do you mean by "displays the xml sent from the server exactly as is - the datagrid keeps the format of the xml" ? does it dump xml content in the grid cells?

Edit: Have you tried doing this?

protected function updateBatchDataGridDP():void{
    task_list_dg.dataProvider = findShipmentBatchesResult.lastResult..batch;
}
Ben
exactly the datagrid displays the xml in raw format. The entire xml content for each column.
Setori
the Data/Services tab looks like findShipmentBatches(searchDate:string, searchHubId: string_: stringshould the return type be xml?
Setori
There seem to be many return type options when I try XML* I would presume a simple String would have sufficed then the client side would be intelligent enough to parse the content.
Setori
added suggestion (Edit) in my response.. (lastResult..batch)
Ben
did you work it out?
Ben
ben I wanted to get back to you but some more urgent issues have come up - i need to squash them first! I promise to get back asap! ;) btw looks like it can work and no i havne't tried that way!
Setori
good luck squashing!
Ben
So finally back ;) anyway, I gave that way a bash I just get a Flash / Flex Error 1061 error. So I presume something is wrong. Secondly I have tried to change the format to <node rd="xxx0" sss="xxx0" etc="etc0" /> <node rd="xxx1" sss="xxx1" etc="etc1" /><node rd="xxx2" sss="xxx2" etc="etc2" />This approach also seems not to work.Any ideas?
Setori
btw the datagrid displays the exact xml text as above in one row and is repeated for every column.
Setori
a post lower Ben mentions the use of the @ sign in the grid. So please don't be a dumb ass like me and forget it.
Setori
ahh. Well i'm glad you got it sorted!
Ben
A: 

had to resort to this monstrosity ----> is there a better way???

        protected function updateBatchDataGridDP():void{
            var batches:XML = new XML(findShipmentBatchesResult.lastResult);
            task_list_dg.dataProvider = batches.batch;
            var task_list_col1:AdvancedDataGridColumn = new AdvancedDataGridColumn();
            task_list_col1.dataField = "@rd";
            task_list_col1.headerText = "Receiving date";
            var task_list_col2:AdvancedDataGridColumn = new AdvancedDataGridColumn();
            task_list_col2.dataField = "@mt";
            task_list_col2.headerText = "Msg type";
            var task_list_col3:AdvancedDataGridColumn = new AdvancedDataGridColumn();
            task_list_col3.dataField = "@ssd";
            task_list_col3.headerText = "SSD";
            var task_list_col4:AdvancedDataGridColumn = new AdvancedDataGridColumn();
            task_list_col4.dataField = "@sss";
            task_list_col4.headerText = "Shipping site";
            task_list_status.text = batches.batch.@sss;
            var task_list_col5:AdvancedDataGridColumn = new AdvancedDataGridColumn();
            task_list_col5.dataField = "@fn";
            task_list_col5.headerText = "File name";
            var task_list_col6:AdvancedDataGridColumn = new AdvancedDataGridColumn();
            task_list_col6.dataField = "@bn";
            task_list_col6.headerText = "Batch number";
            var myColumns:Array = new Array();
            myColumns.push(task_list_col1);
            myColumns.push(task_list_col2);
            myColumns.push(task_list_col3);
            myColumns.push(task_list_col4);
            myColumns.push(task_list_col5);
            myColumns.push(task_list_col6);
            task_list_dg.columns = myColumns;
        }

with this xml structure:

<batches>
    <batch rd="2010-04-23 16:31:00.0" mt="SC1REVISION01" ssd="2010-02-18 00:00:00.0" sss="Quanta" fn="Revision 1-DF-Ocean-SC1SUM-Quanta-PACT-EMEA-Scheduled Ship Date 20100218.csv" bn="SHA201004230033" />
    <batch rd="2010-04-23 16:32:14.0" mt="SC1" ssd="2010-02-11 00:00:00.0" sss="Quanta" fn="DF-Ocean-SC1SUM-Quanta-PACT-EMEA-Scheduled Ship Date 20100211.csv" bn="SHA201004230043" />
    <batch rd="2010-04-23 16:35:51.0" mt="PRESHIP" ssd="2010-02-15 00:00:00.0" sss="Quanta" fn="DF-Ocean-PRESHIPSUM-Quanta-PACT-EMEA-Scheduled Ship Date 20100215.csv" bn="SHA201004230045" />
</batches>
Setori
You shouldn't have to do all, that's not right.You can specify and @attribute in the column tags:<mx:AdvancedDataGridColumn headerText="Receiving date" dataField="@rd"/>
Ben
oh man this is the reason ..... my grid doesn't have the @ sign! and the example I copied off the internet makes use of it. yes mate now I see my mistake! please make another answer and Ill assign the right answer to you :)
Setori
yes it was the @ sign -> i think I need rest. thanks so much mate.
Setori