5 Replies Latest reply on Apr 26, 2010 7:37 AM by EWN-CMI

    data binding combo box to mysql

    vijaybajikar

      I am new to flex but i am learning flex. i want to know a simple example that would help me connect combo box to mysql table.

        • 1. Re: data binding combo box to mysql
          Matt Le Fevre Level 4

          how do you want to connect it?

           

          i'm guessing so whenever you change something in the combo box, it also updates in your mysql?

          • 2. Re: data binding combo box to mysql
            kubens Level 2

            I am using an enhanced combox component which makes using a comobox more comfortable as the original component does.

             

            package net.woocoom.components
            {
                import spark.components.ComboBox;
                import spark.events.IndexChangeEvent;
               
                public class ComboBox extends spark.components.ComboBox
                {
                   
                    /**
                     * @private
                     * Field that contains the name of binded field
                     */
                    private var _dataField:String;
                    public function get dataField():String
                    {
                        return _dataField;
                    }       
                    [Bindable] public function set dataField(value:String):void
                    {
                        if (_dataField == value)
                            return;
                       
                        _dataField = value;
                    }

                    /**
                     * @private
                     * Field that contains the value of selected item.
                     */
                    private var _value:*;
                    [Bindable ("valueChanged")]
                    public function get value():*
                    {
                        var value:* = selectedItem;
                        if (dataField != '' && selectedItem.hasOwnProperty(dataField))
                        {
                            value = selectedItem[dataField];
                        }
                       
                        return value
                    }
                    public function set value(newValue:*):void
                    {
                        if (dataField != '' && newValue.hasOwnProperty(dataField))
                        {
                            if (_value == newValue[dataField])
                                return;
                           
                            _value = newValue[dataField];
                        }
                        else
                        {
                            if (_value == newValue)
                                return;
                           
                            _value = newValue;
                        }
                       
                        // synchronize selected index with assigned value
                        var index:int=-1;
                        for (var i:int=0; i <dataProvider.length; i++)
                        {
                            if (dataProvider[i] != null &&
                                dataProvider[i].hasOwnProperty(dataField) &&
                                dataProvider[i][dataField] == _value)
                            {
                                index=i;
                                break;
                            }
                        }
                        selectedIndex=index;
                       
                        // fire event for data binding
                        dispatchEvent(new Event("valueChanged"));
                    }
                   
                    /**
                     * Constructor
                     */        
                    public function ComboBox()
                    {
                        super();
                        addEventListener(IndexChangeEvent.CHANGE, function(event:IndexChangeEvent):void{ value = selectedItem; });           
                    }
                   
                }
            }

             

            1. dataProvider

            Used to link a table.

             

            2. labelField

            Defines which field of linked table is shown in the combobox.

             

            3. dataField

            Defines which field of linked table is providing the value of selected item of the combobox.

             

            4. value

            Contains the value of selected item of the combobox.

             

            In your form code you can use it easily as below:

             

            <components:ComboBox id="statusComboBox" dataProvider="{listResultLookupTableStatus.lastResult}" labelField="name" dataField="id" value="@{valueObject.status.id}" />

             

            You can find a running example on my playground. The data of 'News Channel' and 'News Status' are simple lookup tables which were used inside the 'News' formular for dropdown lists.

             

            I know it is a little bit tough and short explained but in case that you need further tutorials then this page could be an interesting place for you Learn  Flex in a week

            • 3. Re: data binding combo box to mysql
              vijaybajikar Level 1

              Hi Kuben,

              Could you be little elobarative about the code. Basic aim you want to acheive(Problem) & code refers to what(Solution). I am confussed.

              Thanx buddy.

              • 4. Re: data binding combo box to mysql
                vijaybajikar Level 1

                hi Grizzzzzzzzzz,

                 

                I want to connect flex combo box to mysql using PHP Service. To be very frank using remoting.(AMFPHP Method). I am able to connect to datagrid but not combo box. Why?

                • 5. Re: data binding combo box to mysql
                  EWN-CMI Level 1

                  <mx:ComboBox id="cb_ID" dataProvider="{myArrFromAMF}"  prompt="{EitherBoundorSTATIC}" labelField="mySQLcolumn" x="12" y="0" width="61"/>

                   

                  where cb_ID = Flex component ID

                  myArrFromAMF=your query Result arraycollection (just like a dataGrid)

                  EitherBoundorSTATIC = this is the prompted item in the combo box - like "Please Select" or default to the value already stored through binding (though I have not figured this one out yet)

                  labelField=the column from the lookup table to use