ComboBox and e4x dataProvider labelField

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. Add column to dataprovider
      this seems to be an unresolved issue that many are experiencing . . an answer would be stellar . .
  3. #2

    Default 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

  4. #3

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139