DataGrid + http does not work

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default DataGrid + http does not work

    I try to fill a DataGrid from live XML data over http, but the grid
    desperately stays empty.
    The code is :

    <mx:HTTPService id="catalogContents" contentType="application/xml"
    method="GET" protocol="http" resultFormat="xml"
    url="http://localhost:8080/protocore/getCatalogContents"
    fault='alert(event.fault.faultstring,"",mx.control s.Alert.OK)'
    result='alert("Catalog OK","",mx.controls.Alert.OK)'>

    <mx:DataGrid id="catalogGrid" height="100%" width="100%"
    dataProvider="{catalogContents.result.element}">


    Returned XML is like :
    <?xml version="1.0" encoding="utf-8"?>
    <elements>
    <element Key="Key" Name="Name" Dir="Dir" lang="lang" nloc="nloc"
    npar="npar" UNKNOWN1="UNKNOWN1" UNKNOWN2="UNKNOWN2" Status="Status"
    Anom="Anom" label="label0" />
    <element Key="BAT000000" Name="COA034" Dir="A1/PRG" lang="Cobol"
    nloc="944" npar="649" UNKNOWN1="58" UNKNOWN2="" Status="CORRECT"
    Anom="OK" label="label1" />
    <element ...>
    </elements>

    I know that the Server part is OK, as I am able to display raw XML
    code in the following TextArea:
    <mx:TextArea text="{catalogContents.result}"/>

    I tried the same, with XML compiled statically, and it works :

    <mx:Model id="catalogContentsModel"
    ource="D:\\src\\Flex\\Phoenix-proto\\cataloContents.xml" />

    <mx:DataGrid id="catalogGrid"
    dataProvider="{catalogContentsModel.result.element }">

    Help would be greatly needed, I tried many different combinations of
    returned XML without success (like returning <mx:Array>/<mx:Object>
    tags, specifying the object attributes as XML attributes or as XML
    elements, nothing work)

    Am I *really* an idiot as I seem to be the only one with this problem
    ?:disgust;[url]http://localhost:8080/protocore/getCatalogContents[/url]

    kohinoor75 Guest

  2. Similar Questions and Discussions

    1. Http sessions work but Https does not?? (IE cacheing bug?)
      I'm using PHP 4.32 + Apache and testing with IE under W2K. When I call pages using HTTP everything works fine, users can log in and out, the data...
    2. Chart with http data does not work
      I try to create a chart with live http data. I cannot figure how to make the chart appear correctly. With the same code, if I bind statically the...
    3. HTTP Services for DataGrid
      why is it that, when we send a web request for some data from a .jsp or .xml file, for a datagrid , we dont get the result displayed on the DataGrid...
    4. Added CheckBox to a DataGrid Doesn't work with DataGrid.Enabled=False
      I have created a Template Column and Added to a Datagrid, which contains a checkBox. The column is not Binded to any column of the Dataset, but is...
    5. FORMS only work if you HTTP
      FORMS only work if you upload using http, do not upload forms using ftp. It is a frontpage thing, you must have front page extensions on your web...
  3. #2

    Default Re: DataGrid + http does not work

    Hi man,

    i had the same problem and as I could not fond an Xpath way to do something
    like this

    <mx:DataGrid id="myDataGrid">
    <mx:dataProvider>{catalogContents.result.element }</mx:dataProvider>
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn columnName="element[@Key]" headerText="Key
    Number"/>
    <mx:DataGridColumn columnName="element[@Name]" headerText="The
    Name"/>
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>

    Accessing a specific attribute depending on it s name...

    What i did is reformat my xml to something like this:

    <elements>
    <element>
    <Key>BAT000000</Key>
    <Name>COA034</Name>
    <Dir>A1/PRG</Dir>
    etc...
    </element>
    <element>
    <Key>BAT11111</Key>
    <Name>COA066</Name>
    <Dir>A1/PRG</Dir>
    etc...
    </element>
    </elements>

    and then access it like this:

    <mx:DataGrid id="myDataGrid">
    <mx:dataProvider>{catalogContents.result.element }</mx:dataProvider>
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn columnName="Key" headerText="Key Number"/>
    <mx:DataGridColumn columnName="Name" headerText="The Name"/>
    <mx:DataGridColumn columnName="Dir" headerText="Direction"/>
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>

    It sux a bit but I think that schemantically speaking it s more correct to
    have all these as children nodes rather than attributes.

    Hope this helps./

    Mani


    twoei22 Guest

  4. #3

    Default Re: DataGrid + http does not work

    The basic problem is that XML is hierarchical, and the Datagrid is tabular(a 2
    dimensional array). I had so much trouble in the beginning using XML with a
    datagrid that I just wrote a function that reads the XML and builds a 2dArray,
    and my troubles went away.

    I tried to solve this withoug doing that, but duplicated the unexpected
    behavior that a model populated statically works fine, but one populated using
    binding (with the same XML) does not. here is the sample app that shows the
    behavior.

    Oh, I can get it to work sort of by using the childNodes property(remember,
    dataGrid wants an array of items, and childNodes produces an array), but that
    produces an extra blank line for the implicit textNode.

    It would be nice to solve this once and for all.

    Tracy

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
    initialize="initApp()">

    <mx:Script><![CDATA[
    private var gXMLDoc:XMLNode;
    private var gaXMLData:Array;
    private function initApp():Void
    {
    var sXML:String =
    "<elements>" +
    "<element Key='Key' Name='Name' Dir='Dir' lang='lang' nloc='nloc' " +
    "Anom='Anom' label='label0' />" +
    "<element Key='BAT000000' Name='COA034' Dir='A1/PRG' lang='Cobol' " +
    "Anom='OK' label='label1' />" +
    "<elements>"

    gXMLDoc = mx.utils.XMLUtil.createXML(sXML);
    gaXMLData = gXMLDoc.firstChild.childNodes

    }//

    ]]></mx:Script>

    <mx:Model id="modelXMLB">{gXMLDoc}</mx:Model>

    <mx:Model id="modelXML">
    <elements>
    <element Key="Key" Name="Name" Dir="Dir" lang="lang" nloc="nloc"
    Anom="Anom" label="label0" />
    <element Key="BAT000000" Name="COA034" Dir="A1/PRG" lang="Cobol"
    Anom="OK" label="label1" />
    </elements>
    </mx:Model>

    <mx:DataGrid id="dgSource" dataProvider="{gaXMLData}" rowCount="3">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn headerText="Key" columnName="Key" />
    <mx:DataGridColumn headerText="Name" columnName="Name" />
    <mx:DataGridColumn headerText="Dir" columnName="Dir" />
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>


    <mx:DataGrid id="dgSourceModelB" dataProvider="{modelXMLB.elements.element}"
    rowCount="3">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn headerText="Key" columnName="Key" />
    <mx:DataGridColumn headerText="Name" columnName="Name" />
    <mx:DataGridColumn headerText="Dir" columnName="Dir" />
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>

    <mx:DataGrid id="dgSourceModel" dataProvider="{modelXML.elements.element}"
    rowCount="3">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn headerText="Key" columnName="Key" />
    <mx:DataGridColumn headerText="Name" columnName="Name" />
    <mx:DataGridColumn headerText="Dir" columnName="Dir" />
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>

    <mx:Button label="Button1" click="alert(modelXMLB.toString())"/>
    <mx:Button label="Button2" click="alert(modelXML.toString())"/>
    </mx:Application>

    ntsiii Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139