Ask a Question related to Macromedia Flex General Discussion, Design and Development.
-
GregHunt #1
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 getting
anything in my combobox. It is empty. Here is my combobox declaration:
<mx:ComboBox id="department" labelField="Department" >
<mx:dataProvider>
<mx:Array>
<mx:Object>{mx.utils.ArrayUtil.toArray(employeeRO. getCollege(coa.selectedItem))
}</mx:Object>
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
My method is as follows:
public Object[] getCollege(String campus) {
System.out.println("campus = " + campus);
ArrayList list=new ArrayList();
System.out.println("1111");
if (campus.equals("1")) {
list.add("45");
list.add("55");
} else if (campus.equals("2")) {
list.add("65");
list.add("75");
} else if (campus.equals("4")) {
list.add("15");
list.add("25");
}
System.out.println("array = " + list);
return list.toArray();
}
I'm sure this isn't that hard, but I'm stumped. Any help would be
appreciated. Thanks.
GregHunt 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... -
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... -
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... -
Add column to dataprovider
this seems to be an unresolved issue that many are experiencing . . an answer would be stellar . . -
How to populate a DataProvider with XML and AS only
Hi there, after having spent 2 hours, I decided to get some help from you. Here's what I'd like to do. I have an XML file that I'd like to... -
ntsiii #2
Re: Combobox Dataprovider
Ok, I don't do much RemoteObject, but here are some suggestions that may get
you moving.
First, I don't like to bind directly to data service results because it is so
hard to debug. Instead of doing you dataProvider as you show:
Declare an instance variable(global) to hold the dataProvider array
Bind that array to the Combobox dataProvider
Create a result handler function, and in that assign the result to the variable
Call the result handler from the result event of the remote object.
The benefits of this is that you can determine if your datacall is bieng sent
and the data received. You can, using a debugger, or Trace statements, examine
the structure of the result object in order to determine the correct way to
reference the array that the comboBox needs.
I have created an example of using a Remote Object to poplate a combo box that
is based on the flex samples. It is posted here:
[url]http://www.cflex.net/showfiledetails.cfm?ChannelID=1&Object=File&object ID=18[/url]
Note that it uses AS to manipulate the request objext, again instead of using
binding. I'll paste the mxml example below for your convenience as well.
Tracy
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
verticalGap="10">
<mx:Script>
var empList; //this variable is bound to the employee datagrid dataProvider
private function getEmployees():Void
{
var sMethodName:String = "getList"; //Put the operation name in
a var
var oRequest:Object = employeeRO[sMethodName].arguments; //get a
reference to the method's argument object
oRequest.deptId = dept.selectedItem.data; //put the deptId
Name/Value pair in the arguments object
var call = employeeRO[sMethodName].send(); //Invoke the call
}
//handler for the web service result event
private function onResult(oEvent):Void
{
empList=oEvent.result //causes the data to display in the DG
}
</mx:Script>
<mx:RemoteObject id="employeeRO" source="samples.explorer.EmployeeManager"
result="onResult(event)" fault="alert(event.fault.faultstring,
'Error')">
<mx:method name="getList" />
</mx:RemoteObject>
<mx:HBox>
<mx:Label text="Select a department:"/>
<mx:ComboBox id="dept" width="150">
<mx:dataProvider>
<mx:Array>
<mx:Object label="Engineering" data="ENG"/>
<mx:Object label="Product Management" data="PM"/>
<mx:Object label="Marketing" data="MKT"/>
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
<mx:Button label="Get Employee List" click="getEmployees()"/>
</mx:HBox>
<mx:DataGrid dataProvider="{empList}" width="100%">
<mx:columns>
<mx:Array>
<mx:DataGridColumn columnName="name" headerText="Name"/>
<mx:DataGridColumn columnName="phone" headerText="Phone"/>
<mx:DataGridColumn columnName="email" headerText="Email"/>
</mx:Array>
</mx:columns>
</mx:DataGrid>
</mx:Application>
ntsiii Guest
-
ntsiii #3
Re: Combobox Dataprovider
Oops, I notice I am actually populating a DataGrid, but the theory is the same.
ntsiii Guest
-
ntsiii #4
Re: Combobox Dataprovider
One more thing, data calls are asynchronous. You must either bind the result or use a result handler. You cannot call a dataservice and use the result in the same function.
ntsiii Guest
-
ntsiii #5
Re: Combobox Dataprovider
Still one more thing!
The 60 day trial reverts to a perpetual Developers license after the 60 days,
so effectively you can develop for free, you just can't deploy.
And the Flex builder license does NOT continue. So if you can use another
editor like Eclipse, consider that. I personally like Flex Builder.
Here are some Flex resources. Note especially cflex and flexauthority.
Flex sites/blogs:
[url]http://www.cflex.net/showfaq.cfm?Object=faq&channelID=1&faqtype=&defaul tfields=&[/url]
defaultValues=
[url]http://www.cflex.net/[/url]
[url]http://www.flexauthority.com/[/url]
[url]http://weblogs.macromedia.com/mxna/[/url]
[url]http://www.flexdaddy.info/[/url]
[url]http://www.clinttredway.com/blog/[/url]
[url]http://www.richinternet.de/blog/[/url]
[url]http://www.everythingflex.com[/url]
Flex style Explorer:
[url]http://www.markme.com/mc/archives/FlexStyleExplorer.html[/url]
Documentation:
[url]http://livedocs.macromedia.com/flex/15/asdocs_en/index.html[/url]
[url]http://www.macromedia.com/go/flex15_java_livedocs[/url]
[url]http://www.macromedia.com/cfusion/knowledgebase/index.cfm[/url]
Lists:
[url]http://www.macromedia.com/cfusion/webforums/forum/categories.cfm?catid=346[/url]
[url]http://groups.yahoo.com/group/flexcoders/[/url]
Bugs/enhancement requests:
[url]http://www.macromedia.com/support/email/wishform/[/url]
ntsiii Guest
-
peterent #6
Re: Combobox Dataprovider
Greg,
Take a step back for a second. Tracy's idea of not binding directly to data
service results is a good idea, especially if you just starting out and
unfamiliar with what you got.
First, do this: <mx:method name="getCollege"
result="handleGetCollege(event.result)" /> and make that part of your
employeeRO RemoteObject.
Then write the handleGetCollege method: function handleGetCollege(result).
Then run your app in Flex Builder, but turn on the Network Monitor tool (on the
tabs at the bottom, look for one labeled Network Monitor and when you click it,
there's a checkbox on the far left. Turn that on and then run your application).
You'll see the RPC result come back. Now you can see what Flex is seeing.
In the code below for your dataProvider for your ComboBox is written to be an
Array of an Array. That's because you have the <mx:Array> tag and inside of it
are making sure your results are an array with the ArrayUtil.toArray method.
The ComboBox won't work like that. This would be better:
<mx:ComboBox
dataProvider="{mx.utils.ArrayUtil.toArray(employee RO.getCollege(coa.selectedItem
))}" ... />
Now take a look at what you are getting back from the server. The ComboBox,
but DEFAULT expects each item in its Array to either be a simple String (
["apples","oranges","grapes"]) or if an Object, to have a label field: [
{label:"apples",data:1000}, {label:"oranges",data:2030}].
If your data from the server does not have a field called "label" then you
need to tell the ComboBox what field it should use for the label. For example,
if your data is: [{product:"apples",quantity:1000},...] then do this:
<mx:ComboBox dataProvider="see above" labelField="product" ... />
The labelField property identifies the field from each item to use as the
display.
HTH
Peter
peterent Guest



Reply With Quote

