5 Replies Latest reply on Aug 26, 2010 2:03 AM by flex4

    chained combobox

    ideaddict

      Hi

       

      I want to build an address book, in which user can select his country through combobox, which then filtered cities in next combo box with respect to selected country. Can someone help me to build this code successfully as am new to programming.

       

      Regards

        • 1. Re: chained combobox
          Farore

          Hi,

           

          It's too much code to provide an example you can actually work with but I'll try to get you on the road a little bit with how I woulkd approach this.

           

          This could be something to work with:

           

          - You need to create a database with a few tables, like countries and cities.

          - The cities table contain all the cities ofcourse with a foreign key to the correct country (foreignkey is the id of the country it belongs to)

          - In your Flex application you have services which provide the country and city data. ( like getCountries() and getCities() ) These services return collections containing CountryVO's and CityVO's. These are so called value objects containing properties for these objects (CountryVO: id, name, iso and CityVO: id, name, country_fk)

          - First you get all the countries from a service and use the result to fill the first combobox with all the countries.

          - On this combobox you define a change event and in this eventhandler you can see what is the current selectedItem for the countryComboBox. Let's say you selected The Netherlands, so the selectedLabel would be 'The Netherlands' and the selectedItem is a CountryVO. CountryVO.as is a class you created containing all the properties for a country, like id, name, iso-code etc etc. These properties are saved in the database as well, so the country table in your database contains columns id, name, iso-code etc.

          - With this value you call a service that gets all the cities that have a foreign key to this country. The foreign key is the id of the country you selected.

          So in this case you would select a country -> The Netherlands (which has id 12 for example). Now you can use this to call a service getCities(Long countryId) { select * from cities where country_fk = countryId etc etc } and retrieve all the cities with a foreign key to this country and use the resultSet to set the dataProvider for the city combobox.

           

          Start -> getCountries() (backend service) -> countryCombo dataprovider = serviceResult.

          User selects a country -> change handler fires -> getCities for selected country (backedn service) -> cityCombo dataprovider = serviceResult

          User selects a city. Done.

           

          Now I hope this makes a little sense, else you should probably dive into code examples to learn a little bit more about this before actually start diving in the deep.

           

          Good luck!

          1 person found this helpful
          • 2. Re: chained combobox
            flex4 Level 2

            Hi

             

                     Use xml to achieve this.. In xml mention ur stuff and load that xml to that ArrayCollection and use that ArrayCollection to display value in combobox..  once u select one country from the combobox then u will fetch the relavent states into another combobox...

             

             

                          Use array to add the data to the combobox or arraycollection label field to add data to the combobox

            1 person found this helpful
            • 3. Re: chained combobox
              Vackar Level 2

              flex4 wrote:

               

              Hi

               

                       Use xml to achieve this.. In xml mention ur stuff and load that xml to that ArrayCollection and use that ArrayCollection to display value in combobox..  once u select one country from the combobox then u will fetch the relavent states into another combobox...

               

               

                            Use array to add the data to the combobox or arraycollection label field to add data to the combobox

               

               

              Yes I would agree with this. There is a pitfall that people sometimes fall into where whenever they want to store something, they choose a relational database. And to be honest you don't need any of the features of a relational database for storing a read only collection of countries / states etc (unless the world is taken over by aliens and they decide to change all of our borders and give the areas new names)

               

              When possible Keep It Simple (KISS)

               

              Thanks,

              Vackar

              • 4. Re: chained combobox
                ideaddict Level 1

                @Farore:

                 

                Thanks a lot for providing me a really great solution with all neccessary detail, i personally like to use databases as it will then easy to update the info. If you can provide me code snippet or any real example for this particular function, i'll be highly thankful to you. I found some real examples in JS, JQuerry & ASP.net so i hope people like them would also be available here to help new-one unconditionally.

                 

                Regards!

                 

                @: flex4

                 

                thanks a lot for this  solution, i hope i'll use it with some static data..

                • 5. Re: chained combobox
                  flex4 Level 2

                  Hi

                   

                                 If u r using relational database that will lead to big code..for this simple task there is no need to make 100's of line and that is useless.. Any way if u decide to use relational database for storing this data . and getting the data.. go for RemoteObject concept and load the data every time into flex application..

                   

                   

                                   when select somethink in combobox send customEvent or someother event to fetch the states from serverside data..