bpurcell.org - Example of Binding XML to a DataGrid in Flex
Calendar
SunMonTueWedThuFriSat
  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      

Subject Archives
Amazon EC2 (15)
ColdFusionMX (155)
Corvette (3)
Flash Lite (4)
Flash Media Server (5)
Flash Player (3)
Flex (39)
General Web Dev (14)
HDTV (3)
Jboss (1)
Jquery (2)
JRun (59)
Max 2003 (3)
Other (33)
PC Hardware (16)
Software (17)
SpatialKey (7)
Wireless (8)
Working Out (1)

RSS Feed
Feed Listing

Site Contents
Home
My Blog
ColdFusion
JRun
Flex
Wireless & Networking
Hardware & Gadgets
HDTV
Software Picks
Pictures
Contact Me
Search


My Articles & Papers
Flex Performance
Server/Client
mm.com Under the Hood
Multiple Instances of CFMX
Multiple Instance Config
NLB with ColdFusion
Clustering CFMX for J2EE
Multi-Tier Hardware LB w CFMX
Cisco CSS & Coldfusion MX
JRun 4 Jini based Clustering
WiFi Growth

2ID Tacweb

Other Hobbys
Body-For-Life Challenge

Personal Projects
Family Pool
Deck Gate

username:
password:
 

 
Viewing Individual Entry / Main
May 26, 2004

I have recieved several questions asking how do I bind XML data to a datagrid? The following code binds a simple XML string that is retrieved through the HTTPService using ColdFusion. ColdFusion could be replaced in this case with a JSP or Servlet. Be aware, there is a known issue with the Flex webservice proxy when you try to invoke XML through a webservice. The XML will be encoded incorrectly and will not decode in the Flex application. The workaround is to use HTTPService and create a .cfm or .jsp page that serves as a gateway.

-----xmlService.cfm-----
<CFSILENT>
<CFSAVECONTENT VARIABLE="employees">
 <employees>
  <employee>
   <id>100</id>
   <name>Brandon Purcell</name>
   <title>Principal Engineer</title>
   <phone>617-555-6971</phone>
  </employee>
  <employee>
   <id>101</id>
   <name>Bill Phillips</name>
   <title>VP Engineering</title>
   <phone>617-555-5555</phone>
  </employee>
 </employees>
</CFSAVECONTENT>
</CFSILENT>
<cfheader  name="content-type" value="text/xml">
<cfsetting enablecfoutputonly="yes" showdebugoutput="no"> 
<CFOUTPUT>#employees#</CFOUTPUT> 
-----end xmlService.cfm-----
------datagridXML.mxml------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" 
  backgroundColor="#FFFFFF" 
  verticalGap="0" 
  initialize="myHTTPDetail.send()">
  
<mx:HTTPService id="myHTTPDetail" showBusyCursor="true" method="GET" 
 url="xmlService.cfm">
</mx:HTTPService>
<mx:DataGrid 
 id="orderGrid" 
 dataProvider="{mx.utils.ArrayUtil.toArray(myHTTPDetail.result.employees.employee)}"
 width="375">
 <mx:columns>
 <mx:Array> 
  <mx:DataGridColumn columnName="id" headerText="Id" width="40"/>
  <mx:DataGridColumn columnName="name" headerText="Name" width="115"/>
  <mx:DataGridColumn columnName="title" headerText="Description" width="130"/>
  <mx:DataGridColumn columnName="phone" headerText="Price"/>
 </mx:Array>
 </mx:columns> 
</mx:DataGrid>
</mx:Application>
------end datagridXML.mxml------

Comments

Hi Brandon,

The webservice is a bug? If is a bug do you know if MM is developing a fix.

great example thanks!

C.


I want to say "The webservice issue is a bug?", sorry


Yes, that bug should be fixed in future releases.


I'm having some trouble with the example. I create the two files and save them in the same directory. When i load the data grid i get an error that says "httpservice fault. a start tag has no corresponding end tag". Any ideas what i'm doing wrong?

Thanks for your patience, i'm new at this.

Chris


Got it to work using this tip:

http://www.cfdev.com/support/kb/index.cfm/fuseaction/single/id/1102

Thanks! Chris


This has been a very common example I find on this topic. But I have a scenario where my XML looks something like this <?xml version="1.0" encoding="utf-8"?> <SRM> <SRMData SRMDataSpace="Main"> <SRMComposite n="RecordSet"> <SRMRow> <Z n="AccountBO.url_">srmBOObj:AccountBO/AccountBO.accountID:2</Z> <Z n="AccountBO.Cust_Last_Name">fatboy</Z> <Z n="AccountBO.Cust_First_Name">Clim</Z> <Z n="AccountBO.accountID" ov="2">2</Z> <Z n="AccountBO.AccountName"/> <Z n="AccountBO.AccountKey">102</Z> <Z n="AccountBO.Cust_Type"/> <Z n="AccountBO.groupID">102</Z> </SRMRow> <SRMRow> <Z n="AccountBO.url_">srmBOObj:AccountBO/AccountBO.accountID:1</Z> <Z n="AccountBO.Cust_Last_Name">Lardy</Z> <Z n="AccountBO.Cust_First_Name">Boy</Z> <Z n="AccountBO.accountID" ov="1">1</Z> <Z n="AccountBO.AccountName"/> <Z n="AccountBO.AccountKey">101</Z> <Z n="AccountBO.Cust_Type"/> <Z n="AccountBO.groupID">101</Z> </SRMRow> </SRMComposite> </SRMData> </SRMData>

How do I display this data??

Thx -- Srikanth


 
Page Render Time:203