title: How to pass two objects to use in a form using thymeleaf?
body: <p>My problem is the following :</p>
  <p>I've 2 differents objects that I've to fill from a single form.</p>
  <p>With 1 object, I simply do in the newFoo.html:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;form th:object=&quot;${foo}&quot; th:action=&quot;@{/foo}&quot; method=&quot;post&quot;&gt;
      &lt;input type=&quot;text&quot; th:field=&quot;*{name}&quot;/&gt;
      &lt;button type=&quot;submit&quot;&gt;Go&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p>and in the FooController:</p>
  <pre><code>@RequestMapping(value = &quot;/foo/new&quot;, method = RequestMethod.GET) 
  public String newFoo(final Foo foo, Model model) { 
      return &quot;newFoo&quot;; 
  } 
  
  @RequestMapping(value = &quot;/foo/new&quot;, method = RequestMethod.POST) 
  public String saveFoo(final Foo foo, final BindingResult bindingResult, Model model) { 
      fooService.save(foo); 
      return &quot;redirect:/foo/new&quot;; 
  } 
  </code></pre>
  <p>Let's say I've an other object bar with a &quot;status&quot; variable in it. How can I do to pass that object so I can submit the input within the same form?</p>
  <p>Like:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;form th:object=&quot;${foo} &amp;&amp; ${bar}&quot; th:action=&quot;@{/foo}&quot; method=&quot;post&quot;&gt;
      &lt;input type=&quot;text&quot; th:field=&quot;*{name}&quot;/&gt;
      &lt;input type=&quot;text&quot; th:field=&quot;*{status}&quot;/&gt;
      &lt;button type=&quot;submit&quot;&gt;Go&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p>So far I tried to do with to fieldset with a th:object in it, that doesn't work, I tried to put two th:object in the form, that doesn't work either.</p>
  <p>The only way I found is to build an other object containing those two objects, and pass it. That works well, but I can't create that kind of object, it's nonsense (even if it works).</p>
  <p>Of course, the objects aren't as simple as Foo and Bar here, otherwise I would have merge those two. But that's not something I can do.</p>
  <p>Is it even possible to pass two objects like that to use in a form ?</p>
  <p>Thanks already.</p>