title: Correct way to implement cascading dropdowns in Spring MVC 3.2.x
body: <p>I'm trying to figure out the correct/optimal way to implement dropdowns using Spring MVC 3.2.x. I have JSP page with 4 dropdowns, 2 cascading and 1 static. Here is the <strong>typical implementation that works:</strong></p>
  
  <pre><code>@Controller
  @RequestMapping("/employeeSearch")
  public class EmployeeSearchController {
  .......
  @ModelAttribute("employeeOrgList")
  public List&lt;EmployeeOrgList&gt; populateOrgList(HttpServletRequest request) {
     return employeeService.getEmployeeOrgList();
  }
  
  @ModelAttribute("employeeSubOrg1List")
  public List&lt;EmployeeSubOrg1List&gt; populateSubOrg1List(HttpServletRequest request) {
     return employeeService.getEmployeeSubOrg1List();
  }
  
  @ModelAttribute("employeeSubOrg2List")
  public List&lt;EmployeeSubOrg2List&gt; populateSubOrg2List(HttpServletRequest request) {
     return employeeService.getEmployeeSubOrg2List();
  }
  
  @ModelAttribute("employeeStatusList")
  public List&lt;EmployeeStatusList&gt; populateStatusList(HttpServletRequest request) {
     return employeeService.getEmployeeStatusList();
  }
  
  ...............
  </code></pre>
  
  <p><strong>The PROBLEM:</strong>
  In above implementations, user chooses employee org list first, page refreshes to populate employee sub org 1 list and when employee selects sub org 1 then sub org 2 is populated and employee status dropdown remains populated. This code works just fine as is. But the PROBLEM is I have 7 RequestMappings in the EmployeeSearchController, including the ones that deal with dropdown selections. So, for every call, I'm hitting database <strong>7 x 4 = 28</strong> times, which i think is unacceptable.</p>
  
  <p>To address the issue I removed @ModelAttribute on all 4 methods and manually added them to the model when the pages is accessed for the first time (RequestMapping set to GET). The JSP loads fine but as soon as I select the employee org list, the employee sub org 1 list gets populated but employee org list and employee status lists are blank. Here are the specific methods:</p>
  
  <pre><code>//This is to initialize
  @RequestMapping(method = { RequestMethod.GET })
  public ModelAndView handlePageEntry(HttpServletRequest request, ModelMap modelMap) {
      EmployeeSearchForm form = new EmployeeSearchForm();
      ModelAndView modelView = new ModelAndView("employeeSearchTile");
      modelView.addAttribute("form", form);
      modelView.addAttribute("employeeOrgList", getEmployeeOrgList());
      modelView.addAttribute("employeeSubOrg1ist", new ArrayList&lt;EmployeeSubOrg1ist&gt;());
      modelView.addAttribute("employeeSubOrg2ist", new ArrayList&lt;EmployeeSubOrg1ist&gt;());
      modelView.addAttribute("employeeStatusList", getEmployeeStatusList());
      return modelView;
  }
  
  //This one is called when we select employee org list
  @RequestMapping(method = { RequestMethod.POST }, params = { "submitAction=employeeOrgSelected" })
  public ModelAndView populateEmployeeSubOrg1(@ModelAttribute(value = "form") EmployeeSearchForm form, ModelMap modelMap) {
     ModelAndView modelView = new ModelAndView("employeeSearchTile");
      modelView.addAttribute("form", form);
      modelView.addAttribute("employeeSubOrg1ist", getEmployeeSubOrg1ist(form.getSelectedEmployeeOrg));
      return modelView;
  }
  </code></pre>
  
  <p>Obviously, I'm neither adding the employee org and employee status list back to the model nor am i setting them up in session (which I do not want to do). And If I want to set them on the model then I've to hit the the database again for those 2 lists. Its better than hitting 28 times but still I want the experts to weigh-in.</p>
  
  <p>SO what is the best way to accomplish this task without so many trips to the database?</p>