title: Conditional th:action in spring
body: <p>I have a <code>form</code> to modify an object. This object can be used in two pages, with the same values.</p>
  
  <p>I would like to have two buttons and depending on the button submited send to one page or another.</p>
  
  <p>Right now my code is something like this:</p>
  
  <pre><code>&lt;!-- Make my action dinamically depending on button submitted --&gt;
  &lt;form action="#" th:action="@{/action}" th:object="${myObject}"
        method="post"&gt;
    &lt;input type="submit" name="new" value="new"/&gt;
    &lt;input type="submit" name="edit" value="edit"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><code>th:action</code> should be dynamic.</p>
  
  <p>I have created method in my controller so depending on the action I can deal with it:</p>
  
  <pre><code>@RequestMapping(value = {"/new", "/edit"}, method = RequestMethod.POST)
  public String handlePost(@RequestParam String action, @ModelAttribute MyObject myObject) {
  
      if (action.equals("new")) {
          //Make some stuff
          return "new";
  
      } else if (action.equals("edit")) {
          //Make some stuff
          return "edit";
      }
  
      return "index";
  }
  </code></pre>
  
  <p>In Thymeleaf docs I have seen something similar but I'm not be able to deal with it.</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>My object is a matrix with N columns rendered in my page. If everything is ok I edit its values, but I can add new columns using <strong>new</strong> action.</p>
  
  <p>I want two buttons and depending which of them go to new or go to edit.
  The object always exist.</p>
  
  <p>Any suggestions?</p>
  
  <p>Thanks</p>