[flexcoders] Re: ComboBox populate list with remoteobject
Actually this is a good question, and I am in the same boat and also do not know the correct way to handle this. I have a value object in my data model that came from a table in a database via a RemoteObject call. The VO has an int field that is a foreign key reference to a record in the people table. I have a combobox that gets its list of people from the people table, including their person_id fields, displays the name field, but I need to bind the combo item to the person_id int field in the VO. This does not seem to be possible out of the box, and it looks like flex3 doesn't have it either. Does this mean I have to manually implement an itemchanged event handler for changes in the combo box, and manually set the selected combo item when the value object is first loaded? And even with this, if the model changes, the view would not see it happen. Is there some way to make this binding? T --- In flexcoders@yahoogroups.com, George Georgiou [EMAIL PROTECTED] wrote: Hi there, I got a remoteobject which loads data from an sql table. I got something like 5 fields for customers. I want to populate a combobox showing the name of the customer and having as a value the customer_id. After Googling it a bit, I have ended up with this: mx:ComboBox id=customer_name dataProvider={customerData} labelField=customer_name/ this works great! But what about the dataField? (at my suprise I have found out that although a labelField does exist - which is cool, a dataField attribute does not exist). How can I bind the customer_id into my combobox? Any ideas? thanks, George
[flexcoders] Re: ComboBox populate list with remoteobject
I think you could get at your data field from wherever you need it by referencing like so: ((customer_name as ComboBox).selectedItem as Customer).customer_id; So for example you could bind a label to that. T --- In flexcoders@yahoogroups.com, George Georgiou [EMAIL PROTECTED] wrote: Hi there, I got a remoteobject which loads data from an sql table. I got something like 5 fields for customers. I want to populate a combobox showing the name of the customer and having as a value the customer_id. After Googling it a bit, I have ended up with this: mx:ComboBox id=customer_name dataProvider={customerData} labelField=customer_name/ this works great! But what about the dataField? (at my suprise I have found out that although a labelField does exist - which is cool, a dataField attribute does not exist). How can I bind the customer_id into my combobox? Any ideas? thanks, George
[flexcoders] Re: ComboBox populate list with remoteobject
I just found a solution. It appears that Flex does not support setting data_field or selectedValue properties. (Why not?!?! This seems like a basic core feature) Ben Forta created a custom combo to sort of do it: http://www.forta.com/blog/index.cfm/2006/11/22/Flex-ComboBox-With-select\ edValue-Support http://www.forta.com/blog/index.cfm/2006/11/22/Flex-ComboBox-With-selec\ tedValue-Support Actually his only uses the .data property. A commenter on his blog posted the best solution: http://www.tristanhauser.com/flex/ExtendedComboBox.mxml http://www.tristanhauser.com/flex/ExtendedComboBox.mxml His lets you set the data_field, although he assumes the selectedValue will only be a String, but it should be fairly easy to change this if needed. T --- In flexcoders@yahoogroups.com, George Georgiou [EMAIL PROTECTED] wrote: Hi there, I got a remoteobject which loads data from an sql table. I got something like 5 fields for customers. I want to populate a combobox showing the name of the customer and having as a value the customer_id. After Googling it a bit, I have ended up with this: mx:ComboBox id=customer_name dataProvider={customerData} labelField=customer_name/ this works great! But what about the dataField? (at my suprise I have found out that although a labelField does exist - which is cool, a dataField attribute does not exist). How can I bind the customer_id into my combobox? Any ideas? thanks, George
[flexcoders] Re: ComboBox populate list with remoteobject
Here's the code for the Adobe BindableComboBox.mxml that's generated by the ColdFusion Application Wizard. This will do what you want. ?xml version=1.0 encoding=utf-8? !-- \ // // Copyright (C) 2003-2006 Adobe Macromedia Software LLC and its licensors. // All Rights Reserved. The following is Source Code and is subject to all // restrictions on such code as contained in the End User License Agreement // accompanying this product. If you have received this file from a source // other than Adobe, then your use, modification, or distribution of this file // requires the prior written permission of Adobe. // // @author Dean Harmon // @author Mike Nimer \ -- mx:ComboBox xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml xmlns=* creationComplete=componentInit() mx:Script ![CDATA[ import mx.utils.ObjectUtil; import mx.controls.Alert; [Bindable] public var valueField:String = ; [Bindable] public var labelFields:Array = []; public function componentInit():void { this.labelFunction = renderLabelFunction; } public function renderLabelFunction(item:Object):String { var result:String = ; if (labelFields.length == 0) { if (labelField != null) { return item[labelField]; } else { return item.toString(); } } else { for(var i:int=0; i labelFields.length; i++) { if (i 0) { result += ; } result += item[labelFields[i]]; } } return result; } override public function set selectedItem(val:Object):void { //Alert.show(valueField +: +ObjectUtil.toString(val)); if (this.valueField != null) { for(var i:int=0; i this.dataProvider.source.length; i++) { var item:Object = this.dataProvider.source[i]; if (item[valueField] == val) { // if it matches, make it selected. this.selectedIndex = i; break; } } } else { super.selectedItem(val); } } public function get selectedItemValue():Object { if (this.valueField != null selectedItem != null) { return selectedItem[valueField]; } else { return text; } } ]] /mx:Script /mx:ComboBox ~randy --- In flexcoders@yahoogroups.com, T [EMAIL PROTECTED] wrote: Actually this is a good question, and I am in the same boat and also do not know the correct way to handle this. I have a value object in my data model that came from a table in a database via a RemoteObject call. The VO has an int field that is a foreign key reference to a record in the people table. I have a combobox that gets its list of people from the people table, including their person_id fields, displays the name field, but I need to bind the combo item to the person_id int field in the VO. This does not seem to be possible out of the box, and it looks like flex3 doesn't have it either. Does this mean I have to manually implement an itemchanged event handler for changes in the combo box, and manually set the selected combo item when the value object is first loaded? And even with this, if the model changes, the view would not see it happen. Is there some way to make this binding? T --- In flexcoders@yahoogroups.com, George Georgiou george1977@ wrote: Hi there, I got a remoteobject which loads data from an sql table. I got something like 5 fields for customers. I want to populate a combobox showing the name of the customer and having as a value the customer_id. After Googling it a bit, I have ended up with this: mx:ComboBox id=customer_name dataProvider={customerData} labelField=customer_name/ this works great! But what about the dataField? (at my suprise I have found out that although a labelField does exist - which is cool, a dataField attribute does not exist). How can I bind the customer_id into my combobox? Any ideas? thanks, George
Re: [flexcoders] Re: ComboBox populate list with remoteobject
This simple task is really very confusing :-( I have been through tutorials, references with comboboxes and Arrays and this really appears very simple there. However when it comes to remoteobject it gets extremenly complicated :-( My guess is.. is there any easy way to convert my ArrayCollection that comes from the RemoteObject into an array which has no problems at all with the combobox? i.e. in order to use this dataprovider in a combobox is very easy! [Bindable] public var cards: Array = [ {label:Visa, data:1}, {label:MasterCard, data:2}, {label:American Express, data:3} ]; [Bindable] public var selectedItem:Object; Can I get a remoteobject return me some date and using some simple AS3 to convert what comes back from my service into this? thanks, George ps: sorry if this sounds like a dump idea - i m not really experianced Flex Developer at all, just started it :-) On 10/15/07, Randy Martin [EMAIL PROTECTED] wrote: Here's the code for the Adobe BindableComboBox.mxml that's generated by the ColdFusion Application Wizard. This will do what you want. ?xml version=1.0 encoding=utf-8? !-- // // Copyright (C) 2003-2006 Adobe Macromedia Software LLC and its licensors. // All Rights Reserved. The following is Source Code and is subject to all // restrictions on such code as contained in the End User License Agreement // accompanying this product. If you have received this file from a source // other than Adobe, then your use, modification, or distribution of this file // requires the prior written permission of Adobe. // // @author Dean Harmon // @author Mike Nimer -- mx:ComboBox xmlns:mx=http://www.adobe.com/2006/mxml; xmlns=* creationComplete=componentInit() mx:Script ![CDATA[ import mx.utils.ObjectUtil; import mx.controls.Alert; [Bindable] public var valueField:String = ; [Bindable] public var labelFields:Array = []; public function componentInit():void { this.labelFunction = renderLabelFunction; } public function renderLabelFunction(item:Object):String { var result:String = ; if (labelFields.length == 0) { if (labelField != null) { return item[labelField]; } else { return item.toString(); } } else { for(var i:int=0; i labelFields.length; i++) { if (i 0) { result += ; } result += item[labelFields[i]]; } } return result; } override public function set selectedItem(val:Object):void { //Alert.show(valueField +: +ObjectUtil.toString(val)); if (this.valueField != null) { for(var i:int=0; i this.dataProvider.source.length; i++) { var item:Object = this.dataProvider.source[i]; if (item[valueField] == val) { // if it matches, make it selected. this.selectedIndex = i; break; } } } else { super.selectedItem(val); } } public function get selectedItemValue():Object { if (this.valueField != null selectedItem != null) { return selectedItem[valueField]; } else { return text; } } ]] /mx:Script /mx:ComboBox ~randy --- In flexcoders@yahoogroups.com, T [EMAIL PROTECTED] wrote: Actually this is a good question, and I am in the same boat and also do not know the correct way to handle this. I have a value object in my data model that came from a table in a database via a RemoteObject call. The VO has an int field that is a foreign key reference to a record in the people table. I have a combobox that gets its list of people from the people table, including their person_id fields, displays the name field, but I need to bind the combo item to the person_id int field in the VO. This does not seem to be possible out of the box, and it looks like flex3 doesn't have it either. Does this mean I have to manually implement an itemchanged event handler for changes in the combo box, and manually set the selected combo item when the value object is first loaded? And even with this, if the model changes, the view would not see it happen. Is there some way to make this binding? T --- In flexcoders@yahoogroups.com, George Georgiou george1977@ wrote: Hi there, I got a remoteobject which loads data from an sql table. I got something like 5 fields for customers. I want to populate a combobox showing the name of the customer and having as a value the customer_id.
RE: [flexcoders] Re: ComboBox populate list with remoteobject
The ComboBox knows how to work with ArrayCollection. No conversion should be needed. What does your ArrayCollectiion data look like when it came from RemoteObject? From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of George Georgiou Sent: Monday, October 15, 2007 12:30 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Re: ComboBox populate list with remoteobject This simple task is really very confusing :-( I have been through tutorials, references with comboboxes and Arrays and this really appears very simple there. However when it comes to remoteobject it gets extremenly complicated :-( My guess is.. is there any easy way to convert my ArrayCollection that comes from the RemoteObject into an array which has no problems at all with the combobox? i.e. in order to use this dataprovider in a combobox is very easy! [Bindable] public var cards: Array = [ {label:Visa, data:1}, {label:MasterCard, data:2}, {label:American Express, data:3} ]; [Bindable] public var selectedItem:Object; Can I get a remoteobject return me some date and using some simple AS3 to convert what comes back from my service into this? thanks, George ps: sorry if this sounds like a dump idea - i m not really experianced Flex Developer at all, just started it :-) On 10/15/07, Randy Martin [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Here's the code for the Adobe BindableComboBox.mxml that's generated by the ColdFusion Application Wizard. This will do what you want. ?xml version=1.0 encoding=utf-8? !-- // // Copyright (C) 2003-2006 Adobe Macromedia Software LLC and its licensors. // All Rights Reserved. The following is Source Code and is subject to all // restrictions on such code as contained in the End User License Agreement // accompanying this product. If you have received this file from a source // other than Adobe, then your use, modification, or distribution of this file // requires the prior written permission of Adobe. // // @author Dean Harmon // @author Mike Nimer -- mx:ComboBox xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml xmlns=* creationComplete=componentInit() mx:Script ![CDATA[ import mx.utils.ObjectUtil; import mx.controls.Alert; [Bindable] public var valueField:String = ; [Bindable] public var labelFields:Array = []; public function componentInit():void { this.labelFunction = renderLabelFunction; } public function renderLabelFunction(item:Object):String { var result:String = ; if (labelFields.length == 0) { if (labelField != null) { return item[labelField]; } else { return item.toString (); } } else { for(var i:int=0; i labelFields.length; i++) { if (i 0) { result += ; } result += item[labelFields[i]]; } } return result; } override public function set selectedItem(val:Object):void { //Alert.show(valueField +: +ObjectUtil.toString(val)); if (this.valueField != null) { for(var i:int=0; i this.dataProvider.source.length; i++) { var item:Object = this.dataProvider.source[i]; if (item[valueField] == val) { // if it matches, make it selected. this.selectedIndex = i; break; } } } else { super.selectedItem(val); } } public function get selectedItemValue():Object { if (this.valueField != null selectedItem != null) { return selectedItem[valueField]; } else { return text; } } ]] /mx:Script /mx:ComboBox ~randy --- In flexcoders@yahoogroups.com http://ups.com/ , T [EMAIL PROTECTED] wrote: Actually this is a good question, and I am in the same boat and also do not know the correct way to handle this. I have a value object in my data model that came from a table in a database via a RemoteObject call. The VO has an int field that is a foreign key reference to a record in the people table. I have a combobox that gets its list of people from the people table, including their person_id fields, displays the name field, but I need to bind the combo item to the person_id int field in the VO. This does not seem to be possible out of the box, and it looks like flex3 doesn't have it either. Does this mean I have to manually implement an itemchanged event handler for changes
RE: [flexcoders] Re: ComboBox populate list with remoteobject
The source property will return the array that the ArrayCollection wraps. But I don't think this is either your problem or solution. The way you get your data into Flex should be irrelevant to how you consume it in a control. An ArrayCollection is an ArrayCollection, regardless of how you get it. Have you debugged the RemoteObject result in the result handler to see that it is what you are expecting? Hmm, before I forget, don't name a variable selectedItem, that is used by the ComboBox and other list controls. Exactly where are you now? What is working and what is not and what is your goal? Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of George Georgiou Sent: Monday, October 15, 2007 3:30 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Re: ComboBox populate list with remoteobject This simple task is really very confusing :-( I have been through tutorials, references with comboboxes and Arrays and this really appears very simple there. However when it comes to remoteobject it gets extremenly complicated :-( My guess is.. is there any easy way to convert my ArrayCollection that comes from the RemoteObject into an array which has no problems at all with the combobox? i.e. in order to use this dataprovider in a combobox is very easy! [Bindable] public var cards: Array = [ {label:Visa, data:1}, {label:MasterCard, data:2}, {label:American Express, data:3} ]; [Bindable] public var selectedItem:Object; Can I get a remoteobject return me some date and using some simple AS3 to convert what comes back from my service into this? thanks, George ps: sorry if this sounds like a dump idea - i m not really experianced Flex Developer at all, just started it :-) On 10/15/07, Randy Martin [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Here's the code for the Adobe BindableComboBox.mxml that's generated by the ColdFusion Application Wizard. This will do what you want. ?xml version=1.0 encoding=utf-8? !-- // // Copyright (C) 2003-2006 Adobe Macromedia Software LLC and its licensors. // All Rights Reserved. The following is Source Code and is subject to all // restrictions on such code as contained in the End User License Agreement // accompanying this product. If you have received this file from a source // other than Adobe, then your use, modification, or distribution of this file // requires the prior written permission of Adobe. // // @author Dean Harmon // @author Mike Nimer -- mx:ComboBox xmlns:mx=http://www.adobe.com/2006/mxml http://www.adobe.com/2006/mxml xmlns=* creationComplete=componentInit() mx:Script ![CDATA[ import mx.utils.ObjectUtil; import mx.controls.Alert; [Bindable] public var valueField:String = ; [Bindable] public var labelFields:Array = []; public function componentInit():void { this.labelFunction = renderLabelFunction; } public function renderLabelFunction(item:Object):String { var result:String = ; if (labelFields.length == 0) { if (labelField != null) { return item[labelField]; } else { return item.toString (); } } else { for(var i:int=0; i labelFields.length; i++) { if (i 0) { result += ; } result += item[labelFields[i]]; } } return result; } override public function set selectedItem(val:Object):void { //Alert.show(valueField +: +ObjectUtil.toString(val)); if (this.valueField != null) { for(var i:int=0; i this.dataProvider.source.length; i++) { var item:Object = this.dataProvider.source[i]; if (item[valueField] == val) { // if it matches, make it selected. this.selectedIndex = i; break; } } } else { super.selectedItem(val); } } public function get selectedItemValue():Object { if (this.valueField != null selectedItem != null) { return selectedItem[valueField]; } else { return text; } } ]] /mx:Script /mx:ComboBox ~randy --- In flexcoders@yahoogroups.com http://ups.com/ , T [EMAIL PROTECTED] wrote: Actually this is a good question, and I am in the same boat and also do not know the correct way to handle this. I have a value object in my data model that came from a table in a database via a RemoteObject call. The VO has an int field
Re: [flexcoders] Re: ComboBox populate list with remoteobject
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Here is what I have done to get a RemoteObject Array into the ComboBox. mx:ComboBox id=cbxSchoolBuilding enabled=true change=DisplayBuildingTeachers(); dataProvider={SchoolBuildingsDP} labelField=LABEL/mx:ComboBox Then within the mx:Script [Bindable] private var SchoolBuildingsDP:Array; private function GetSchoolBuildings_Result(event:ResultEvent):void { SchoolBuildingsDP = ArrayUtil.toArray(event.result); } Now my RemoteObject is mx:RemoteObject id=K12WebServices destination=ColdFusion source=properties.cfc.K12FlexWebService showBusyCursor=true fault=K12WebService_Fault(event) endpoint=http://{ServerName}/flex2gateway/; mx:method name=GetSchoolBuildingsWS fault=GetSchoolBuildings_Fault(event) result=GetSchoolBuildings_Result(event) mx:arguments SiteID{SiteID}/SiteID /mx:arguments /mx:method /mx:RemoteObject George Georgiou wrote: This simple task is really very confusing :-( I have been through tutorials, references with comboboxes and Arrays and this really appears very simple there. However when it comes to remoteobject it gets extremenly complicated :-( My guess is.. is there any easy way to convert my ArrayCollection that comes from the RemoteObject into an array which has no problems at all with the combobox? i.e. in order to use this dataprovider in a combobox is very easy! [Bindable] public var cards: Array = [ {label:Visa, data:1}, {label:MasterCard, data:2}, {label:American Express, data:3} ]; [Bindable] public var selectedItem:Object; Can I get a remoteobject return me some date and using some simple AS3 to convert what comes back from my service into this? thanks, George ps: sorry if this sounds like a dump idea - i m not really experianced Flex Developer at all, just started it :-) On 10/15/07, Randy Martin [EMAIL PROTECTED] wrote: Here's the code for the Adobe BindableComboBox.mxml that's generated by the ColdFusion Application Wizard. This will do what you want. ?xml version=1.0 encoding=utf-8? !-- // // Copyright (C) 2003-2006 Adobe Macromedia Software LLC and its licensors. // All Rights Reserved. The following is Source Code and is subject to all // restrictions on such code as contained in the End User License Agreement // accompanying this product. If you have received this file from a source // other than Adobe, then your use, modification, or distribution of this file // requires the prior written permission of Adobe. // // @author Dean Harmon // @author Mike Nimer -- mx:ComboBox xmlns:mx=http://www.adobe.com/2006/mxml; xmlns=* creationComplete=componentInit() mx:Script ![CDATA[ import mx.utils.ObjectUtil; import mx.controls.Alert; [Bindable] public var valueField:String = ; [Bindable] public var labelFields:Array = []; public function componentInit():void { this.labelFunction = renderLabelFunction; } public function renderLabelFunction(item:Object):String { var result:String = ; if (labelFields.length == 0) { if (labelField != null) { return item[labelField]; } else { return item.toString(); } } else { for(var i:int=0; i labelFields.length; i++) { if (i 0) { result += ; } result += item[labelFields[i]]; } } return result; } override public function set selectedItem(val:Object):void { //Alert.show(valueField +: +ObjectUtil.toString(val)); if (this.valueField != null) { for(var i:int=0; i this.dataProvider.source.length; i++) { var item:Object = this.dataProvider.source[i]; if (item[valueField] == val) { // if it matches, make it selected. this.selectedIndex = i; break; } } } else { super.selectedItem(val); } } public function get selectedItemValue():Object { if (this.valueField != null selectedItem != null) { return selectedItem[valueField]; } else { return text; } } ]] /mx:Script /mx:ComboBox ~randy --- In flexcoders@yahoogroups.com, T [EMAIL PROTECTED] wrote: Actually this is a good question, and I am in the same boat and also do not know the correct way to handle this. I have a value object in my data model that came from a table in a database via a RemoteObject call. The VO has an int field that is a foreign key reference to a record in the people table. I have a combobox that gets its