I will look into this and get back to you.
Check the Help to see if DropDownList controls are supposed to be used if there is only one data object being returned. You would likely need more than one option available for a DropDownList.
The problem you are having is caused by the way the ArrayCollection class is used to handle the data being returned from the XML. The ArrayCollection class is only used when it NEEDS to be used, which Flex considers an XML file with 2 or more data objects in it. This is why it works with two employees vs. one.
When Flex sees there is only one object in the XML, it doesn't consider this as NEEDING the ArrayCollection class, Flex defaults the data object to the ObjectProxy class.
If there were no objects in the XML file, you would recieve an error saying the return type was "null".
Since this is not a "bug" so to speak, you should consider using a conditional and the ArrayUtil.toArray() method to handle a single result vs. multiple results. The ArrayUtil.toArray() method will convert the ObjectProxy class to the Array class and thus allow it to be handled by the ArrayCollection class.
P.S. dont forget to import the ArrayUtil package
public var employees:ArrayCollection = new ArrayCollection();
if (event.result.employees.employee is ObjectProxy)
employees = new ArrayCollection( ArrayUtil.toArray(event.result.employees.employee) );
employees = event.result.employees.employee;
The API documentation for combo box states for:
- dataProvider - "Set of data to be viewed. Some classes use a simple array. Others use XML heirarchies. Still others use a class instance. In general, do not make assumptions about the composition of a dataProvider."
- length - "Number of items in the dataProvider. Note that this is not necessarily the number of items displayed."
So I am none the wiser.
I would have thought that a list of one would be acceptable. For now I also assume that would be the case.
In relation to the comment
"When Flex sees there is only one object in the XML, it doesn't consider this as NEEDING the ArrayCollection class, Flex defaults the data object to the ObjectProxy class." ...
I can appreciate this from an implementation perspective, merely relying on the data presented, but I also think it is important to consider the context in which that data is presented, i.e. the client WANTING a collection, even if it is a collection of one (in this case) or zero.
I suspect that the data provider is unaware of the context and hence there is no solution except for the client in such cases to handle the possibility of an empty or single-item collection and respond with alternative GUI components.
The consequences are that instead of a "simple" declaration, robust code would need to (psuedo code):
if empty collection
handle empty collection with some component
else if single item collection
maybe convert into array collection and render in a combo box or just render it in a text field
render it in a combo box as planned.
I have the same problem as you