title: Binding Map values onto spring MVC form
body: <p>I have an issue when trying to bind values from the jsp onto a map in my Spring Form for use in my controller.  I've exhausted my resources at work and I'm hoping that someone can point me in the right direction.  Here is my setup (semi-sudo code).</p>
  
  <p>I need to prepopulate the key's in the map so that the id's on the jsp match to the keys on the map.  Then when the user makes selections on the ui, update the values of those keys and bind it to the form.  I have in other cases put a BindingResult on the @RequestMapping and see that the myMap fields are being suppressed which I'm guessing means they aren't being bound correctly.</p>
  
  <p>I think my main issue or what could be the cause is that I'm not pre-populating the map in the correct spot.</p>
  
  <p>First time asking a question on here if theres more needed let me know and I can provide additional information.</p>
  
  <p>The <strong>JSP</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form:form id="fooForm" modelAttribute="fooForm" action="formDecision" method="POST"&gt;
    &lt;c:forEach items="${fooForm.myMap}" var="myMap" varStatus="status"&gt;         
      &lt;form:input type="hidden" id="${myMap.key}" path="myMap['${myMap.key}']" value=""/&gt;     &lt;/c:forEach&gt;
  &lt;/form:form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>fooFORM.java</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public class fooForm {
      public Map&lt;String, String&gt; myMap;
    
      //other fields....
    
      public void setMyMap(Map&lt;String, String&gt; map) {
          this.myMap = map;
      }
  
      public void getMyMap() {
          return this.myMap;
      }
  
      //other getters and setters....
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Controller.java</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public static Map&lt;String, String&gt; aMap;
  
  static {
      aMap.put("key", "value");
      ......
  }
  
  @RequestMapping(value="initializeFooForm", method="GET")
  public ModelAndView initializeForm(@ModelAttribute("fooForm") FooForm fooForm) {
      fooForm.setMyMap(aMap);
  
      return new ModelAndView("view", "fooForm", fooForm);                   
  }
  
  @RequestMapping("fooForm")
  public ModelAndView getFooDecisions(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("fooForm") FooForm fooForm) {
      do work on fooForm...
  
      return new ModelAndView("view", "fooForm", fooForm);                   
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I've tried these posts:</p>
  
  <p><a href="https://stackoverflow.com/questions/4511647/spring-binding-values-in-a-map">Spring binding values in a Map</a></p>
  
  <p><a href="http://viralpatel.net/blogs/spring-mvc-hashmap-form-example/" rel="nofollow noreferrer">http://viralpatel.net/blogs/spring-mvc-hashmap-form-example/</a>
  <a href="http://developer.ucsd.edu/develop/user-interface/building-a-form/form-binding-with-collections.html" rel="nofollow noreferrer">http://developer.ucsd.edu/develop/user-interface/building-a-form/form-binding-with-collections.html</a></p>
  
  <p>and some others to no avail.</p>