title: Spring JSP: Trouble with spring form with modelAttribute="" and path=""
body: <p>Using the modelAttribute="" tag and the path="" tag don't make sense to me when there is only one string to be passed to the controller. However, when a form has multiple textboxes, it actually does make sense to have an object model for them. This way the modelAttribute tag represents the object, i.e. "Employee", and the path tags represent the fields, i.e. "firstName", "lastName", "salary".</p>
  
  <p>What do you do when you only want to pass one string though? I shouldn't have to create a "Key" class with a "key" field with getKey() and setKey() or any of that craziness just to pass a string to a controller method, right? What is the convention in this case?  </p>
  
  <p>If I just do <code>model.addAttribute("key", "")</code> when the page loads, I get:</p>
  
  <pre><code>org.springframework.beans.NotReadablePropertyException: Invalid property 'key' 
  of bean class [java.lang.String]: Bean property 'key' is not readable or has an invalid 
  getter method: Does the return type of the getter match the parameter type of the setter?
  </code></pre>
  
  <p>If I delete the modelAttribute="key" tag I get:</p>
  
  <pre><code>java.lang.IllegalStateException: Neither BindingResult nor plain target object for 
  bean name 'command' available as request attribute
  </code></pre>
  
  <p><strong>JSP</strong></p>
  
  <pre><code>&lt;form:form method="post" action="myAction" modelAttribute="key"&gt;
     &lt;td&gt;
         &lt;form:input path="key" value="${myValue}"/&gt;
         &lt;input type="submit" value="Submit"/&gt;
     &lt;/td&gt;
  &lt;/form:form&gt; 
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>@RequestMapping(value = "/myAction", method = RequestMethod.POST)
  public String handleMyActionRequest(@ModelAttribute("key") String key, Model model) {
  
      // do stuff with key string.
  
      return HOME_PAGE_REDIRECT;
  }
  </code></pre>
  
  <p>What is the convention for passing a single string to a controller method when a form is submitted, without having to create a new class?</p>