2 Replies Latest reply on Mar 25, 2009 7:12 AM by Gregory Lafrance

    Populate data grid

    senthilkumarvirtusa
      hi i need to populate the data grid in mxml.
      For that i need to call jsp from flex to get data.
        • 1. Re: Populate data grid
          alice_data Level 1
          Hi,

          There is an easy to read document at http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_2.html, and even though it is about PHP, you could use the url as JSP.

          HTH.

          Alice
          • 2. Re: Populate data grid
            Gregory Lafrance Level 6
            This code may help once you get your data back. It accesses a data file but many of the principles are the same.

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
            creationComplete="dataRequest.send()">
            <mx:Script>
            <![CDATA[
            import mx.events.ListEvent;
            import mx.collections.XMLListCollection;
            import mx.rpc.events.ResultEvent;

            [Bindable] private var dataxlc:XMLListCollection = new XMLListCollection();

            private function resultHandler(e:ResultEvent):void {
            var xmllist:XMLList = new XMLList(e.result..product);
            dataxlc = new XMLListCollection(xmllist);
            }
            ]]>
            </mx:Script>
            <mx:HTTPService id="dataRequest" useProxy="false" resultFormat="e4x"
            result="resultHandler(event)" url="data3.xml"/>
            <mx:DataGrid dataProvider="{dataxlc}" rowCount="{dataxlc.length}">
            <mx:columns>
            <mx:DataGridColumn dataField="@partnum"
            headerText="Part Number"/>
            <mx:DataGridColumn dataField="name"
            headerText="Product Name"/>
            </mx:columns>
            </mx:DataGrid>
            </mx:Application>
            ------------------------------- data3.xml -----------------------------------
            <?xml version="1.0" encoding="utf-8"?>
            <products>
            <product partnum="001">
            <name>Desk</name>
            </product>
            <product partnum="002">
            <name>Chair</name>
            </product>
            <product partnum="003">
            <name>Table</name>
            </product>
            <product partnum="004">
            <name>Bookshelf</name>
            </product>
            <product partnum="005">
            <name>Lamp</name>
            </product>
            <product partnum="006">
            <name>Computer</name>
            </product>
            <product partnum="007">
            <name>Monitor</name>
            </product>
            </products>