Shaun Mccran

My digital playground

24
J
U
N
2008

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.

view plain print about
1<cffunction name="returnCombo" returntype="query" access="remote" hint="Returns a query to populate Combo box.">
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:

view plain print about
1private function handleCombo(event:ResultEvent):void
2    {
3    ComboId.dataProvider = event.result;
4    }

This function maps the remote object result directly to the combo box. Which looks like this:

view plain print about
1<mx:ComboBox id="ComboId" prompt="Prompted Option" />

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Back to top