views:

672

answers:

1

I am trying display values in a datagrid in my application. I have all the values as an xml file. I had only one set of record n the XML file, to fill only one row of the data grid. While trying to store the values from the XML file to an Array Collection in the application File using the code, i.e.,

<mx:Model id="reviewList" source="assets/reviewList.xml"/>
<mx:ArrayCollection id="reviewlist" source="{reviewList.Item}"/>

I get an error, saying

Error No# 1034: Type coercion failed cannot convert mx.utils::ObjectProxy to Array.

But If I have two record sets in the XML file, it works fine. If there is only one set, I get the above said error? What is the problem in this case?

Here is my xml file:

<ReviewList>
<Item>
 <ReviewId>1123</ReviewId>
 <TaskType>User Requirement Specification</TaskType>
 <RequestId>1223</RequestId>
 <ItemCodeVersion>URS - 1</ItemCodeVersion>
 <ReviewStartDate>29-Sep-2009</ReviewStartDate>
 <Status>Review In Progress</Status>
 <Reviewer>MR.RISHU GHOSE</Reviewer>
 <OpenDefect>0</OpenDefect>
 <CasualAnalysisPending>0</CasualAnalysisPending>
 <CloseDefects>0</CloseDefects>
 <VerifiedDefects>0</VerifiedDefects>
</Item>

</ReviewList>

And this is the datagrid where I want the details to be displayed.

<mx:DataGrid id="reviewDG" dataProvider="{reviewlist}" variableRowHeight="true" width="100%" height="200" 
            horizontalScrollPolicy="off">

<mx:columns>
 <mx:DataGridColumn headerText="Review Id" dataField="ReviewId" textAlign="center" />

 <mx:DataGridColumn headerText="Task Type" dataField="TaskType" textAlign="center"/> 

 <mx:DataGridColumn headerText="Request Id" dataField="RequestId" textAlign="center"/> 

 <mx:DataGridColumn headerText="Item Code-Ver" dataField="ItemCodeVersion" textAlign="center" headerWordWrap="true"/> 

 <mx:DataGridColumn headerText="Review Start Date" dataField="ReviewStartDate" textAlign="center" headerWordWrap="true"/>

 <mx:DataGridColumn headerText="Status" dataField="Status" textAlign="center"/>

 <mx:DataGridColumn headerText="Reviewer" dataField="Reviewer" textAlign="center"/>

 <mx:DataGridColumn headerText="Open Defect" dataField="OpenDefect" textAlign="center" headerWordWrap="true"/> 

 <mx:DataGridColumn headerText="Casual Analysis Pending" dataField="CasualAnalysisPending" textAlign="center" headerWordWrap="true"/>

 <mx:DataGridColumn headerText="Close Defects" dataField="CloseDefects" textAlign="center" headerWordWrap="true"/>

 <mx:DataGridColumn headerText="Verified Defects" dataField="VerifiedDefects" textAlign="center" headerWordWrap="true"/>

 <mx:DataGridColumn headerText="Review Details" dataField="ReviewDetails" width="65" headerWordWrap="true"> 
  <mx:itemRenderer> 
    <mx:Component> 
  <mx:Label text="View" click="outerDocument.onViewClick()"/> 
    </mx:Component> 
  </mx:itemRenderer> 
 </mx:DataGridColumn> 


</mx:columns>
  </mx:DataGrid>

There may be cases in my application where i need only one record to be displayed in the datagrid. In such cases how do I resolve this error?

+3  A: 

My understanding is that the <mx:Model> declaration should probably be instead. Honestly never used either, but from my reading here it seems that the mx:Model declaration turns the xml into an object (ObjectProxy). So based on your problem, I'm guessing that if it encounters a single "Item", it turns that into a key:value pair (e.g., simple Object) within the proxy. When it encounters multiple "Item"s, it puts them into an Array instead. That is, the structure of the contents is likely unpredictable.

So if you use mx:XML (with format="e4x"),and use an XMLListCollection instead of ArrayCollection, you can use {reviewList.Item} as your source.

Glenn
Ya.. You are correct. On using the XML and XMLListCollection tags, I do not get that problem. Even with one record, it is displayed in the datagrid. Thanks for ur help.
Angeline Aarthi