PDA

View Full Version : binding HttpService.lastResult to XMLListCollection


Can I
04-29-2007, 08:58 PM
hi,

it is written in flex dev guide that to bind lastResult to XMLListCollection you would do sth like this:
<mx:XMLListCollection id="xc" source="{employeeWS.getList.lastResult}"/>

so I try...

113.xml:

<?xml version="1.0" encoding="utf-8"?>
<mindmap name="113">
<branch name="pierwsza gałąź">
<branch name="podgałąź" />
</branch>
<branch name="druga gałąź"/>
</mindmap>


and app:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
creationComplete="mindmapService.send()">

<mx:HTTPService id="mindmapService" url="mindmaps/113.xml"
resultFormat="e4x" showBusyCursor="true" />

<mx:XMLList id="xmlList">
<mindmap name="113">
<branch name="pierwsza gałąź">
<branch name="podgałąź" />
</branch>
<branch name="druga gałąź"/>
</mindmap>
</mx:XMLList>

<mx:XMLListCollection id="xmlListCollection" source="{ mindmapService.lastResult }" />

<mx:Tree dataProvider="{ xmlListCollection }" labelField="@name" width="200" />

</mx:Application>


but I'm getting
1118: Implicit coercion of a value with static type Object to a possibly unrelated type XMLList
error

so how to bind this loaded data?

batmitra
05-04-2007, 02:45 PM
Hi

The xmlListCollection can't bind directly to a Httpservice, at least , reading de docs i did'nt get that idea, it can only bind to a xmlList , so on your code if you delete any references to httpservice and change your source on xml Listcollection to the name of the xmlList you have, that works fine.

I have a question, why do you use a XmlListCollection to fill a tree control?
That can be accomplished with a response from the Httpservice.

Can I
05-04-2007, 02:56 PM
Hi

The xmlListCollection can't bind directly to a Httpservice, at least , reading de docs i did'nt get that idea, it can only bind to a xmlList
but the lastResult is XMLList in this case
// actually it's not - it's an XML object and it can be done with AS handler

private function onResult( event : ResultEvent ) : void {
xmlListCollection.source = new XMLList( event.result );
}

it's a pity you can't to the same in MXML only

so on your code if you delete any references to httpservice and change your source on xml Listcollection to the name of the xmlList you have, that works fine.
yes, I know that, I put the xmlList for tests there

I have a question, why do you use a XmlListCollection to fill a tree control?
That can be accomplished with a response from the Httpservice.
I didn't know that ;)
plus in the real world I have to bind to a VO's property being XML or XMLList which gets updated from HTTPService call

dr_zeus
05-04-2007, 06:50 PM
Does this work?

<mx:XMLListCollection id="xc" source="{mindmapService.lastResult.branch}"/>

Can I
05-04-2007, 06:55 PM
it does, but the root tag is missing obviously

dr_zeus
05-04-2007, 07:03 PM
That's because with the root tag, the data's type is XML. An XMLListCollection needs an XMLList.

NickZA
11-03-2008, 12:07 PM
I have a question, why do you use a XmlListCollection to fill a tree control?
That can be accomplished with a response from the Httpservice.

I just wanted to point out that I found myself thinking this way, but couldn't get things working using this route.

On Adobe LiveDocs, they recommend you do not do it this way. As implied in this thread, it limits your control over the incoming data.

Although raw data objects are automatically wrapped in an ArrayCollection object or XMLListCollection object when used as the value of a data provider component's dataProvider property, they are subject to the following limitations:

Raw objects are often not sufficient if you have data that changes, because the data provider component does not receive a notification of any changes to the base object. The component therefore does not get updated until it must be redrawn due to other changes in the application, or if the data provider is reassigned. At that time, it gets the data again from the updated raw object.
Raw objects do not provide advanced tools for accessing, sorting, or filtering data. For example, if you use an Array as the data provider, you must use the native Adobe® Flash® Array methods to manipulate the data.

...from here on livedocs (http://livedocs.adobe.com/flex/3/html/help.html?content=about_dataproviders_2.html)