Ask a Question related to Macromedia Flex General Discussion, Design and Development.
-
dan19460 #1
ComboBox and e4x dataProvider labelField
Okay, this should be a common use case but, of course, I am struggling with it.
I simply want to populate a mx:ComboBox from the result of a Webservice but I
am having trouble getting the ComboBox to pick up the appropriate xml for the
labelField. The result of the Webservice call is e4x. The result of the
Webservice (verified) is:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<mb:MarketBasketsResponse
xmlns:mb="http://mycompany.com/market-basket/schemas">
<mb:MarketBasket basketId="1">
<mb:Name>Client A</mb:Name>
</mb:MarketBasket>
<mb:MarketBasket basketId="2">
<mb:Name>Client B</mb:Name>
</mb:MarketBasket>
</mb:MarketBasketsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
(note the namespace)
In my webservice callback result handler :
private function handleMarketBasketsResult(event:ResultEvent):void {
var x:XML = new XML(event.result);
namespace mb =
"http://mycompany.com/market-basket/schemas";
x.addNamespace(mb);
mbCombo.dataProvider = x..mb::MarketBasket as XMLList;
mbCombo.data = "mb::basketId";
mbCombo.labelField = "mb::Name";
}
Unfortunately, the combo box gets populated with the entire XML string
beginning with the MarketBasket elements (making for a big combo box!).
This has to be a simple error on my behalf but I'm exhausted trying to find
the answer. Is there someplace in the LiveDocs that points out a similar usage
scenario?
Thanks.
Dan
dan19460 Guest
-
Select a dataProvider with a ComboBox
When the user makes a selection from a ComboBox (of a list of subjects), how do I tell the dataProvider of the display element that the dataProvider... -
Tree labelfield not aligned correctly
I have been using an XML feed to drive a tree control - to show a directory structure. When I start the app and do the load of the data at least one... -
ComboBox bound to a ComboBox: doesn't work until .changeevent
Hi, i have two ComboBoxes getting DataProvider from an XMl doc. The XML nodes look like this: <activity label="aerobics"> <level label="low... -
Combobox Dataprovider
I have just downloaded the 60 day trial edition, and am trying to populate a combobox from a java method that returns an array object. I am not... -
Add column to dataprovider
this seems to be an unresolved issue that many are experiencing . . an answer would be stellar . . -
dan19460 #2
Re: ComboBox and e4x dataProvider labelField
Upon further research, the problem is the Namespace. It seems that you cannot
use a namespace prefix in the labelField attribute of a mx:ComboBox. I was
able to get the label set correctly in the combo by using a labelFunction
instead of setting the labelField:
private function getMarketBasketName(data:Object):String {
return data.mb::Name;
}
My Webservice event handler callback now looks like this:
private function handleMarketBasketsResult(event:ResultEvent):void {
mbCombo.dataProvider = event.result.mb::MarketBasket;
}
Note that "mb" is now defined (scoped) as a module Namespace variable since
I'm using it in multiple functions. Also, I do not set any labelField property
of the combo since I've defined a labelFunction of "getMarketBasketName".
I've also noted a similar phenomenon with binding a DataGrid to an XML type
that contains a Namespace. To get values to appear in the columns, I've had to
write labelFunctions for every column. Yuk!!! There may be a way to do this
with a single function if you follow a convention or do something with string
replacement but....
Unless someone posts an alternative technique, the lesson I have learned is
always convert an XML data type to an object (using manual or automated
serialization) and bind the data controls to that object (or array of objects)
instead of directly to the XML. It will save the headaches of writing all
these little functions to deal with namespaces.
dan19460 Guest
-
dan19460 #3
Re: ComboBox and e4x dataProvider labelField
Just to complete the loop (BTW, I feel like I'm talking to myself)... Here is a
function that you could use to dynamically extract the label from a child node
with a namespace declaration. Note that this is only necessary with namespaces
as I haven't had any trouble populating a data grid based upon the standard
dataField attribute of the DataGridColumn otherwise. In this example, I use
the setting of the dataField attribute (WITHOUT ANY REFERENCE TO NAMESPACES)
passed into a function defined as the labelFunction for each column:
private function getItemValue(data:Object, column:DataGridColumn):String {
return data.child(new QName(mb, column.dataField));
}
I hope this saves others some of the aggravation I experienced on the issue.
I'd still like to see a cleaner handling of namespaces in flex components but
at least this works.
Dan
dan19460 Guest



Reply With Quote

