title: Thymeleaf construct object
body: <p>Im passing a model attribute from controller to thymeleaf form so I could bind object like this:</p>
  
  <pre><code>&lt;div class="container" style="max-width: 600px" th:fragment="signupForm"&gt;
      &lt;form name="f" th:action="@{/signup}" th:object="${userCredentials}" method="post" class="form-horizontal"&gt;
          &lt;input th:placeholder="#{messages.form.email}" type="text" th:field="*{email}"
                 name="email" id="email" class="form-control"/&gt;
          &lt;input th:placeholder="#{messages.form.name}" type="text" th:field="*{name}"
                 name="name" id="name" class="form-control"/&gt;
          &lt;input type="password" th:placeholder="#{messages.form.password}" th:field="*{password}"
                 name="password" id="password"/&gt;
          &lt;button type="submit" th:text="#{messages.form.signup}"&gt;&lt;/button&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>However I'd like to reuse this form as fragment from other views, but I can't do that because the <code>${userCredentials}</code> form object is not initialized. Can I somehow construct this object inside of my view like this?</p>
  
  <pre><code>&lt;div th:if="${userCredentials == null}" th:with="userCredentials=new UserCredentials()"&gt;&lt;/div&gt;
  </code></pre>