Solved

flex datagrid and combobox

Posted on 2009-04-09
30
2,868 Views
Last Modified: 2013-12-24
I have a flex datagrid and some form fields including 2 combo boxes.  Both combo boxes pull in data from my db table.  both are bindable to the datagrid so that when you click on the record in the grid, the item in the combo box is highlighted.  That works great.  However, inside the datagrid, what is being passed back to the grid is the pk id.  It needs to be the other field in the db table.  What would I need to change?
flex app:
 

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" xmlns:ns1="*" viewSourceURL="srcview/index.html" height="100%" borderStyle="none" width="100%">

	<mx:RemoteObject id="ro" destination="ColdFusion" showBusyCursor="true" source="Media.components.Crud">

		<mx:method name="getData" result="getDataResult(event)" />

		<mx:method name="getcbData" result="getCBData(event)" />

		<mx:method name="saveNewData" result="getDataResult(event)" />

		<mx:method name="saveOldData" result="getDataResult(event)" />

		<mx:method name="deleteData" result="getDataResult(event)" />

	</mx:RemoteObject>

	<mx:RemoteObject id="agency" destination="ColdFusion" showBusyCursor="true" source="Media.components.VideoProfessor.Agency2">

		<mx:method name="getagencyData" result="getagencyData(event)" />

	</mx:RemoteObject>

	<mx:Script>

		<![CDATA[

			import mx.rpc.events.ResultEvent;

			import mx.collections.ArrayCollection;

			

			[Bindable] private var gridData:ArrayCollection;

			[Bindable] private var cbData:Array;

			[Bindable] private var agencyData:Array;

			

			

			//on initialize, populate grid and combo boxes!

			private function init():void{

				ro.getData();

				ro.getcbData();

				agency.getagencyData();

			}

			

			private var isNew:Boolean = true;

			

			public function getDataResult(e:ResultEvent):void{

				dg.dataProvider = e.result as ArrayCollection;

				makeNew();

				

			}

			

			private function getCBData(e:ResultEvent):void{

				cbData = e.result as Array;

			}

			

			private function getagencyData(e:ResultEvent):void{

				agencyData = e.result as Array;

			}

			

			private function makeNew():void{

				firstNameFld.text = "";

				lastNameFld.text = "";

				officePhoneFld.text = "";

				agencyId.text = "";

				isNew = true;

			}

			private function save():void{

				if(isNew){

					ro.saveNewData(firstNameFld.text,lastNameFld.text,officePhoneFld.text,agencyId.text);

				}else{

					ro.saveOldData(firstNameFld.text,lastNameFld.text,officePhoneFld.text,agencyId.text,dg.selectedItem.id);

				}

			}

			private function deleteData():void{

				if(dg.selectedIndex > -1 )ro.deleteData(dg.selectedItem.id);

			}

		]]>

	</mx:Script>

	

	<mx:Label text="View your data below." width="1148" height="25" color="#FFFFFF" fontSize="12" fontFamily="Verdana" fontWeight="bold" id="toptext"/>

	<mx:Panel width="1148" height="784" layout="absolute">

		<mx:DataGrid dataProvider="{gridData}" x="10" y="10" width="1108" height="316" id="dg" change="isNew = false">

		</mx:DataGrid>

		<mx:Panel x="10" y="409" width="1108" height="286" layout="absolute">

			

			<!-- fill with first names -->

			<mx:FormItem label="First Name" id="firstnameLbl" x="10" y="70" width="266">

				<ns1:comboBox id="firstNameFld" x="106" y="126"  dataProvider="{cbData}" selectedValue="{dg.selectedItem.firstNameFld}"/>

			</mx:FormItem>

			

			<!-- fill with agency names -->

			<mx:FormItem label="agency" id="agencyLbl" x="305" y="70" width="266">

				<ns1:comboBox id="agencyId" x="106" y="126"  dataProvider="{agencyData}" selectedValue="{dg.selectedItem.agencyId}"/>

			</mx:FormItem>

			

			

			<mx:FormItem label="Last Name" id="lastnameLbl" x="11" y="40">

				<mx:TextInput id="lastNameFld" text="{dg.selectedItem.lastNameFld}"/>

			</mx:FormItem>

			<mx:FormItem label="Office Phone" id="officephoneLbl" x="305" y="40" width="266">

				<mx:TextInput id="officePhoneFld" text="{dg.selectedItem.officePhoneFld}" width="176"/>

			</mx:FormItem>

			

			

			

			

			

		</mx:Panel>

		<mx:Button x="10" y="712" label="Save Record" click="save()"/>

		<mx:Button x="1011" y="712" label="Delete Record" click="deleteData()"/>

		<mx:Button x="115" y="712" label="Add New Record" click="makeNew()"/>

		<mx:Label x="105" y="334" text="Click on the record which will populate the fields below. After making your changes, click Save Record." width="1013" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="normal" id="midtext"/>

		<mx:Label x="10" y="334" text="Edit A Record:" width="97" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="bold" id="midtext0"/>

		<mx:Label x="130" y="355" text="Click Add New Record to clear all fields.  Enter new data, then click Save Record." width="988" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="normal" id="midtext1"/>

		<mx:Label x="10" y="355" text="Add New Record:" width="123" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="bold" id="midtext2"/>

		<mx:Label x="115" y="376" text="Click on the record above.  Then click Delete Record." width="1003" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="normal" id="midtext3"/>

		<mx:Label x="10" y="376" text="Delete Record:" width="112" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="bold" id="midtext4"/>

	</mx:Panel>

</mx:Application>
 
 

Crud.cfc:

<cfcomponent output="false">

	

	<!--- get all data; populate in grid --->

	<cffunction name="getData" access="remote" returntype="Query">

		<cfset var local = {} />

		<cfquery name="local.q" datasource="media">

			select		id, firstNameFld, lastNameFld, officePhoneFld, agencyId

			from		employees

		</cfquery>

		<cfreturn local.q/>

	</cffunction>

	

	

	

	

	<!--- get agencies; populate combo box --->

	<cffunction name="getagencyData" access="remote" returntype="array">

		<cfset local = {} />

		

		<cfquery datasource="media" name="local.q">

			select		*

			from		agency

		</cfquery>

		

		<cfset local.result = arrayNew(1) />

		

		<cfloop query="local.q">

			<cfset local.temp = {} />

			<cfset local.temp['data'] = local.q.agencyId />

			<cfset local.temp['label'] = local.q.agency />

			<cfset arrayAppend(local.result,local.temp) />

		</cfloop>

		

		<cfreturn local.result />

	</cffunction>

	
 
 
 

	

	<!--- get First Name; populate combo box --->

	<cffunction name="getcbData" access="remote" returntype="array">

		<cfset local = {} />

		

		<cfquery datasource="media" name="local.q">

			select		firstNameFld

			from		employeesNames

		</cfquery>

		

		<cfset local.result = arrayNew(1) />

		

		<cfloop query="local.q">

			<cfset local.temp = {} />

			<cfset local.temp['data'] = local.q.firstNameFld />

			<cfset local.temp['label'] = local.q.firstNameFld />

			<cfset arrayAppend(local.result,local.temp) />

		</cfloop>

		

		<cfreturn local.result />

	</cffunction>

	

	

	

	

	<!--- save new record --->

	<cffunction name="saveNewData" access="remote" returntype="Query">

		<cfargument name="firstNameFld" type="string" required="true"/>

		<cfargument name="lastNameFld" type="string" required="true"/>

		<cfargument name="officePhoneFld" type="string" required="true"/>

		<cfargument name="agencyId" type="string" required="true"/>

		

		<cfquery datasource="media">

			insert		

			into		employees

						( firstNameFld, lastNameFld, officePhoneFld, agencyId)

			values		( <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.firstNameFld#"/>,

						  <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.lastNameFld#"/>,

						  <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.officePhoneFld#"/>,

						  <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.agencyId#"/> )

		</cfquery>

		<cfreturn getData() />

	</cffunction>

	

	

	

	

	<!--- save existing record --->

	<cffunction name="saveOldData" access="remote" returntype="Query">

		<cfargument name="firstNameFld" type="string" required="true"/>

		<cfargument name="lastNameFld" type="string" required="true"/>

		<cfargument name="officePhoneFld" type="string" required="true"/>

		<cfargument name="agencyId" type="string" required="true"/>

		<cfargument name="id" type="Numeric" required="true" />

		

		<cfquery datasource="media">

			update		employees		

			set			firstNameFld = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.firstNameFld#" />,

						lastNameFld = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.lastNameFld#" />,

						officePhoneFld = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.officePhoneFld#" />,

						agencyId = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.agencyId#" />

			where		id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" />

		</cfquery>

		<cfreturn getData() />

	</cffunction>

	

	

	

	<!--- delete record --->

	<cffunction name="deleteData" access="remote" returntype="Query">

		<cfargument name="id" type="string" required="true">

		

		<cfquery datasource="media">

			delete

			from		employees

			where		id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" />

		</cfquery>

		<cfreturn getData() />

	</cffunction>

		

</cfcomponent>
 
 
 

Agency2.cfc:

<cfcomponent output="false">

	

	<!--- get agencies; populate combo box --->

	<cffunction name="getAgencyData" access="remote" returntype="array">

		<cfset local = {} />

		

		<cfquery datasource="media" name="local.q">

			select		*

			from		agency

		</cfquery>

		

		<cfset local.result = arrayNew(1) />

		

		<cfloop query="local.q">

			<cfset local.temp = {} />

			<cfset local.temp['data'] = local.q.agencyId />

			<cfset local.temp['label'] = local.q.agencyId />

			<cfset arrayAppend(local.result,local.temp) />

		</cfloop>

		

		<cfreturn local.result />

	</cffunction>

	

</cfcomponent>

Open in new window

0
Comment
Question by:COwebmaster
  • 15
  • 15
30 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 24113934
>> However, inside the datagrid, what is being passed back to the grid is the pk id.  
>> It needs to be the other field in the db table.  What would I need to change?
I don't understand what you're trying to say.
Could you please explain it in other words?
0
 

Author Comment

by:COwebmaster
ID: 24115110
In my db table (called agency), I have 2 columns (agencyId, agency).   My combo box in my flex app show the agencyId, not agency.  Can you please explain what I should change in my flex code or cfcs to make it so that the combo box show the correct column.  Also, the column in the datagrid is also displaying agencyId when it should be pulling in agency data from my db table.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24115223
>> Also, the column in the datagrid is also displaying agencyId when it should be pulling in agency data from my db table.
When I read the lines 12 & 13 of your code and I read the lines 250 & 251 I see why.
Change line 251 being

      <cfset local.temp['label'] = local.q.agencyId />

into

      <cfset local.temp['label'] = local.q.agency />
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24115240
Mistake: changing that line 251 as I mentioned is to resolve the combo box problem.
Still thinking about the datagrid problem...
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24115271
Concerning the datagrid:
In lines 117/118 I see that your query agencyId, not agency

117                  select            id, firstNameFld, lastNameFld, officePhoneFld, agencyId
118                  from            employees
0
 

Author Comment

by:COwebmaster
ID: 24115392
Ok, I fixed all that but now when I click on the record in the datagrid, the item doesn't get selected in the drop down.  In the drop down, I can select another item and click Save Record which works so that good.  Plus I can see the agencies in the drop down and in the datagrid.  Just that last part and we should on our way.
0
 

Author Comment

by:COwebmaster
ID: 24115402
Also, on the Save button, the agencyId is not being saved to the table, but the agency.  It's needs to the agencyId (datatype int in the table).
0
 

Author Comment

by:COwebmaster
ID: 24115443
ok, forget that problem with the drop down item not being highlighted.  It was because the record is insrting a string.
0
 

Author Comment

by:COwebmaster
ID: 24115445
The last problem I see is my last point and that is its insrting agency (string) into the table but it needs to insrt the agencyId.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24115483
>> It's needs to the agencyId (datatype int in the table).
Then why does line 180 reads:

            <cfargument name="agencyId" type="string" required="true"/>

?
0
 

Author Comment

by:COwebmaster
ID: 24115555
yea, that true that needs changed.  however, it's still not passing a numeric value into the table.
0
 

Author Comment

by:COwebmaster
ID: 24115594
Ok, I changed that string to numeric in the crud.cfc:
<cfcomponent output="false">

	

	<!--- get all data; populate in grid --->

	<cffunction name="getData" access="remote" returntype="Query">

		<cfset var local = {} />

		<cfquery name="local.q" datasource="media">

			select		ME.*, A.*

			from		employees ME, agency A

			where ME.agencyId = A.agencyId

		</cfquery>

		<cfreturn local.q/>

	</cffunction>

	

	<!--- get First Name; populate combo box --->

	<cffunction name="getcbData" access="remote" returntype="array">

		<cfset local = {} />

		

		<cfquery datasource="media" name="local.q">

			select		firstNameFld

			from		employeesNames

		</cfquery>

		

		<cfset local.result = arrayNew(1) />

		

		<cfloop query="local.q">

			<cfset local.temp = {} />

			<cfset local.temp['data'] = local.q.firstNameFld />

			<cfset local.temp['label'] = local.q.firstNameFld />

			<cfset arrayAppend(local.result,local.temp) />

		</cfloop>

		

		<cfreturn local.result />

	</cffunction>

	

	<!--- save new record --->

	<cffunction name="saveNewData" access="remote" returntype="Query">

		<cfargument name="firstNameFld" type="string" required="true"/>

		<cfargument name="lastNameFld" type="string" required="true"/>

		<cfargument name="officePhoneFld" type="string" required="true"/>

		<cfargument name="agencyId" type="numeric" required="true"/>

		

		<cfquery datasource="media">

			insert		

			into		employees

						( firstNameFld, lastNameFld, officePhoneFld, agencyId)

			values		( <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.firstNameFld#"/>,

						  <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.lastNameFld#"/>,

						  <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.officePhoneFld#"/>,

						  <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.agencyId#"/> )

		</cfquery>

		<cfreturn getData() />

	</cffunction>

	

	<!--- save existing record --->

	<cffunction name="saveOldData" access="remote" returntype="Query">

		<cfargument name="firstNameFld" type="string" required="true"/>

		<cfargument name="lastNameFld" type="string" required="true"/>

		<cfargument name="officePhoneFld" type="string" required="true"/>

		<cfargument name="agencyId" type="numeric" required="true"/>

		<cfargument name="id" type="Numeric" required="true" />

		

		<cfquery datasource="media">

			update		employees		

			set			firstNameFld = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.firstNameFld#" />,

						lastNameFld = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.lastNameFld#" />,

						officePhoneFld = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.officePhoneFld#" />,

						agencyId = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.agencyId#" />

			where		id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" />

		</cfquery>

		<cfreturn getData() />

	</cffunction>

	

	<!--- delete record --->

	<cffunction name="deleteData" access="remote" returntype="Query">

		<cfargument name="id" type="string" required="true">

		

		<cfquery datasource="media">

			delete

			from		employees

			where		id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.id#" />

		</cfquery>

		<cfreturn getData() />

	</cffunction>

		

</cfcomponent>

Open in new window

0
 

Author Comment

by:COwebmaster
ID: 24115606
So I guess what I need to figure out is how can I display (label) the agency in the drop down but insert the agencyId (data)?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24115618
OK. And does that help?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24115625
>> So I guess what I need to figure out is how can I display (label) the agency in the drop down but insert the agencyId (data)?
You need to fill up your combo with agencyid's and use a labelfunction that "translate's" the agencyId into the agency
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 37

Expert Comment

by:zzynx
ID: 24115636
0
 

Author Comment

by:COwebmaster
ID: 24115754
can't get it work.  It throws an error.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24115827
>> It throws an error.
Mmmm, that's not very informative... ;o)
Complete error message? At what line?
0
 

Author Comment

by:COwebmaster
ID: 24115974
Sorry, this is the error I get when the page loads is:

Error #1081: Property @agencyId not found on Object and there is no default value
flex app:

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" xmlns:ns1="*" viewSourceURL="srcview/index.html" height="100%" borderStyle="none" width="100%">

	<!-- Crud.cfc -->

	<mx:RemoteObject id="ro" destination="ColdFusion" showBusyCursor="true" source="Media.components.Crud">

		<mx:method name="getData" result="getDataResult(event)" />

		<mx:method name="getcbData" result="getCBData(event)" />

		<mx:method name="saveNewData" result="getDataResult(event)" />

		<mx:method name="saveOldData" result="getDataResult(event)" />

		<mx:method name="deleteData" result="getDataResult(event)" />

	</mx:RemoteObject>

	<!-- Agency2.cfc -->

	<mx:RemoteObject id="agency" destination="ColdFusion" showBusyCursor="true" source="Media.components.Agency2">

		<mx:method name="getagencyData" result="getagencyData(event)" />

	</mx:RemoteObject>

	<mx:Script>

		<![CDATA[

			import mx.rpc.events.ResultEvent;

			import mx.collections.ArrayCollection;

			import mx.utils.StringUtil;

			

			[Bindable] private var gridData:ArrayCollection;

			[Bindable] private var cbData:Array;

			[Bindable] private var agencyData:Array;

			

			private function agencyId_labelFunc(item:Object):String {

                return StringUtil.substitute("{0} ({1})", item.@agencyId, item.@agency);

            }
 

			//on init, populate grid and combo boxes!

			private function init():void{

				ro.getData();

				ro.getcbData();

				agency.getagencyData();

			}

			

			private var isNew:Boolean = true;

			

			public function getDataResult(e:ResultEvent):void{

				dg.dataProvider = e.result as ArrayCollection;

				makeNew();

			}

			

			private function getCBData(e:ResultEvent):void{

				cbData = e.result as Array;

			}

			

			private function getagencyData(e:ResultEvent):void{

				agencyData = e.result as Array;

			}

			

			private function makeNew():void{

				firstNameFld.text = "";

				lastNameFld.text = "";

				officePhoneFld.text = "";

				agencyId.text = "";

				isNew = true;

			}

			private function save():void{

				if(isNew){

					ro.saveNewData(firstNameFld.text,lastNameFld.text,officePhoneFld.text,agencyId.text);

				}else{

					ro.saveOldData(firstNameFld.text,lastNameFld.text,officePhoneFld.text,agencyId.text,dg.selectedItem.id);

				}

			}

			private function deleteData():void{

				if(dg.selectedIndex > -1 )ro.deleteData(dg.selectedItem.id);

			}

		]]>

	</mx:Script>

	

	<mx:Label text="View your data below." width="1148" height="25" color="#FFFFFF" fontSize="12" fontFamily="Verdana" fontWeight="bold" id="toptext"/>

	<mx:Panel width="1148" height="784" layout="absolute">

		<mx:DataGrid dataProvider="{gridData}" x="10" y="10" width="1108" height="316" id="dg" change="isNew = false">

		</mx:DataGrid>

		<mx:Panel x="10" y="409" width="1108" height="286" layout="absolute">

			

			<!-- fill with first names -->

			<mx:FormItem label="First Name" id="firstnameLbl" x="10" y="70" width="266">

				<ns1:comboBox id="firstNameFld" x="106" y="126"  dataProvider="{cbData}" selectedValue="{dg.selectedItem.firstNameFld}"/>

			</mx:FormItem>

			

			<!-- fill with agency names -->

			<mx:FormItem label="agency" id="agencyLbl" x="305" y="70" width="266">

				<ns1:comboBox id="agencyId" x="106" y="126"  dataProvider="{agencyData}" labelFunction="agencyId_labelFunc" selectedValue="{dg.selectedItem.agencyId}"/>

			</mx:FormItem>

			

			

			<mx:FormItem label="Last Name" id="lastnameLbl" x="11" y="40">

				<mx:TextInput id="lastNameFld" text="{dg.selectedItem.lastNameFld}"/>

			</mx:FormItem>

			<mx:FormItem label="Office Phone" id="officephoneLbl" x="305" y="40" width="266">

				<mx:TextInput id="officePhoneFld" text="{dg.selectedItem.officePhoneFld}" width="176"/>

			</mx:FormItem>

			

			

			

			

			

		</mx:Panel>

		<mx:Button x="10" y="712" label="Save Record" click="save()"/>

		<mx:Button x="1011" y="712" label="Delete Record" click="deleteData()"/>

		<mx:Button x="115" y="712" label="Add New Record" click="makeNew()"/>

		<mx:Label x="105" y="334" text="Click on the record which will populate the fields below. After making your changes, click Save Record." width="1013" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="normal" id="midtext"/>

		<mx:Label x="10" y="334" text="Edit A Record:" width="97" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="bold" id="midtext0"/>

		<mx:Label x="130" y="355" text="Click Add New Record to clear all fields.  Enter new data, then click Save Record." width="988" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="normal" id="midtext1"/>

		<mx:Label x="10" y="355" text="Add New Record:" width="123" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="bold" id="midtext2"/>

		<mx:Label x="115" y="376" text="Click on the record above.  Then click Delete Record." width="1003" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="normal" id="midtext3"/>

		<mx:Label x="10" y="376" text="Delete Record:" width="112" height="25" color="#990000" fontSize="11" fontFamily="Verdana" fontWeight="bold" id="midtext4"/>

	</mx:Panel>

</mx:Application>

Open in new window

0
 
LVL 37

Expert Comment

by:zzynx
ID: 24116110
>> private function agencyId_labelFunc(item:Object):String {
>>     return StringUtil.substitute("{0} ({1})", item.@agencyId, item.@agency);
>> }
Well, it's not that easy.
To make the above work, your combo box has to contain objects that has both the "agencyId" and "agency" properties.
Which apparently isn't the case currently. (it just contains String's)
Hence the error.

What I suggested was, that your combo should contain agencyId's (again) - because needed for the update.
Then if you have a dictionary/map to translate an id to the agency name you could use that in your  label function. (input:agency id - output:agency name)
0
 

Author Comment

by:COwebmaster
ID: 24116129
Ok, that makes sense.  So how would I bring both values into the combo box using the following?
<cfcomponent output="false">

	

	<!--- get agencies; populate combo box --->

	<cffunction name="getAgencyData" access="remote" returntype="array">

		<cfset local = {} />

		

		<cfquery datasource="media" name="local.q">

			select		*

			from		agency

		</cfquery>

		

		<cfset local.result = arrayNew(1) />

		

		<cfloop query="local.q">

			<cfset local.temp = {} />

			<cfset local.temp['data'] = local.q.agencyId />

			<cfset local.temp['label'] = local.q.agency />

			<cfset arrayAppend(local.result,local.temp) />

		</cfloop>

		

		<cfreturn local.result />

	</cffunction>

	

</cfcomponent>

Open in new window

0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 24116241
Could you try if this works:

private function agencyId_labelFunc(item:Object):String {
   return StringUtil.substitute("{0} ({1})", item.@data, item.@label);
}

and if not try this:

private function agencyId_labelFunc(item:Object):String {
  return item.toString();
}

and tell me what the items in your combo box look like.

I almost have to go offline...
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24116335
Going off line now. See you...
0
 

Author Comment

by:COwebmaster
ID: 24116423
Ok, the top didn't work, got an error:

Error #1081: Property @data not found on Object and there is no default value

i tried the bottom and it loaded fine but the combo box now has [object] [object] in it
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24135628
So, one combo box item now displays as

[object] [object]

?

One toString() call resulting in [object][object].
That would mean that the item coming in (in agencyId_labelFunc) is an array (of 2 objects in this case)

In that case, try applying this agencyId_labelFunc function

private function agencyId_labelFunc(item:Object):String {
    var classInfo:XML = describeType(item);
    return classInfo.@name.toString();
}

and let me know what you see in your combo box for each element. (I expect you see something that contains "Array")
If that is the case change the method like this:

private function agencyId_labelFunc(item:Object):String {
    var classInfo:XML = describeType(Array(item)[0]);
    return classInfo.@name.toString();
}

and again let me know what you see in your combo box for each element.
0
 

Author Comment

by:COwebmaster
ID: 24154201
ok, I'll check it out.
0
 

Author Closing Comment

by:COwebmaster
ID: 31568730
Thx!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24603361
thanx 4 axxepting
0
 

Author Comment

by:COwebmaster
ID: 24603379
sorry it took so long.  I'll manage those better in the future.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24603478
All right :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now