|
Method for populating a flex combo box from cfc |
Many of the flex form elements can be populated directly from the data output from a coldfusion cfc, as long as you get the format right!
Here's the best way I've found to painlessly populate a combo box in flex.
The CFC
Starting with the coldfusion service, create your component (cfc) and a method to return the the combo values.We need to perform a query of queries, as coldfusion returns a query object in uppercase, and flex is case sensitive, so we lowercase alias our returned fields in the second query.
2
3 <cfquery name="propQuery" datasource="yourDB">
4 Select field1, field2 From dbo.table
5 </cfquery>
6
7 <cfquery dbtype="query" name="qGetComboFields">
8 Select field1 as data, field2 as label
9 from propQuery
10 Order by field1
11 </cfquery>
12
13 <cfreturn qGetComboFields>
14 </cffunction>
This way we are provided with a query object that contains named pairs of data:value, and label:value, in lowercase.
Which is EXACTLY what the mx:combobox in flex requires as an input.
Flex bit
Setup your remoting in flex, and handle the result like this:2 {
3 ComboId.dataProvider = event.result;
4 }
This function maps the remote object result directly to the combo box. Which looks like this:
There are no comments for this entry.
[Add Comment] [Subscribe to Comments]