0

I want in multiple dropdown list but query from database. For example when I select the country "USA", and I want a dropdown list cities and when I select a city "New York" I want the dropdown list it's district. Is there anyway to do that with ajax or jquery with Spring MVC Framework? I am appreciate for any answers. thank you.

1
  • 1
    yes, it's possible. Do you have a more concrete question?
    – JB Nizet
    Commented Mar 11, 2012 at 7:33

3 Answers 3

1

There is no "out of the box" solution for this kind of thing. You can use elements of SpringMVC to make this happen, but it'll be mostly custom code on your side.

1
Controller:

@RequestMapping("/cities/{country}.json")
public @ResponseBody getCities(@PathVariable String country) {
    --return a List<City> or List<String or whatever-- 
}

Javascript

$.get('/context/controller/cities/USA.json', function(response) {
    for(var i = 0, length = response.length; i < length; i++) {
        --do something with the city--
    }
});

Edit: As far as making sure that the city value is distinct, I'd do that on the server side

Cheers, Mark

0

You can map methods in your mvc controller to particular urls. for example:

@RequestMapping(value = "/some/url/here", method = RequestMethod.GET)
public [your response type here] getCitiesList{

}

When you select something from the drop down list append the selection to the url as a request parameter which can then be used in your mvc application to query your database for the cities to populate in your next drop down list.

Repeat this process for each list.

Slightly vague answer to a vague question but I hope it helps :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.