title: Spring MVC second Post method @ModelAttribute is null
body: <p>I have a form that has two buttons, a submit button and an update button.</p>
  
  <p>Here is the JSP: </p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;!-- Bootstrap core CSS !--&gt;
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"&gt;
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"&gt;&lt;/script&gt;
  
  &lt;!--  Custom scripts/styles for this page  !--&gt;
  &lt;script type="text/javascript" src="${pageContext.request.contextPath}/static/script/jquery.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="${pageContext.request.contextPath}/static/script/script.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/style.css" /&gt; 
  
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;!-- General Information Form --&gt;
      &lt;form:form id="form" method="POST" action="${pageContext.request.contextPath}/create" modelAttribute="task"&gt;
      &lt;div id="general"&gt;
              &lt;table style="width: 224px;"&gt;
                  &lt;tr&gt;
                      &lt;td colspan="2"&gt;&lt;form:select id="systemType" path="systemType" items="${systemTypes}" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td id="buffer"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td colspan="2"&gt;&lt;form:select  id="userName" path="user.fullName" items="${userFullNames}" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td id="buffer"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td style="width: 50%;"&gt;&lt;label for=line&gt;&lt;b&gt;Line: &lt;/b&gt;&lt;/label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;form:select  path="location.line" items="${lines}" id="line"/&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td id="buffer"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td style="width: 50%;"&gt;&lt;label for=position&gt;&lt;b&gt;Position: &lt;/b&gt;&lt;/label&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;form:select path="location.position" items="${positions}" id="position" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td id="buffer"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td colspan="2"&gt;
                      &lt;input id="submitButton" type="submit" name="submit" value=Submit /&gt;
                      &lt;input style="display:none;" id="updateButton" type="submit" name="update" value="Update" /&gt;
                      &lt;input id="cancel" style="float: right;" type="Reset" value="Cancel"  /&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/div&gt;
  &lt;/form:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is my controller:</p>
  
  <pre><code>@Controller
  @RequestMapping("/")
  public class HomeController {
  
  private TaskService taskService;
  
  @Autowired
  public void setTaskService(TaskService taskService) {
      this.taskService = taskService;
      }
  
  @RequestMapping(value = "/", method = RequestMethod.GET)
  public String initForm(Model model, HttpServletRequest request) {
      Task task = new Task();
  
      model.addAttribute("task", task);
      return "home";
  }
  
  @RequestMapping(value="/create", params="submit", method = RequestMethod.POST)
  public String submitForm(@ModelAttribute("task")Task task,BindingResult result, Model model) { 
  
      taskService.create(task);
      return "redirect:/";
  }
  
  @RequestMapping(value="/create", params="update", method = RequestMethod.POST)
  public String updateForm(@ModelAttribute("task")Task task, BindingResult result, Model model) {
  
     System.out.println("Updating: " + task.toString());          
     taskService.update(task);
  
     return "redirect:/";
  }
  </code></pre>
  
  <p>The idea being that hitting the submit button will make a new item, and the update button will edit an existing one. The two <code>.POST</code> methods have different parameters specified to distinguish them.</p>
  
  <p><strong>The submit button is working as expected</strong>. However when the update button is pressed a <code>Task</code> object is delivered to the <code>updateForm</code> controller method - but all of its fields are null.</p>
  
  <p>I am not sure why the form is binding the fields to the <code>Task</code> correctly on the <code>submit</code> method, but seemingly creating a new <code>Task</code> and not binding it at all in the <code>update</code> method.</p>
  
  <p>I am inclined to just combine these methods into a single controller method and use some Java logic to determine whether to submit/update based on the parameter - but am curious as to what I'm missing and why this doesn't work.</p>