title: Thymeleaf's form dont return the object to controller class's method
body: <p>I have a SpringBoot-MVC Java application with JPA/Hibernate, using a H2 database to store data and I'm trying to read and change lines of this database through web browser. I had success with the reading, but the edit page's form with thymeleaf does not send the object I alterated to controller class.</p>
  <p>The formulary:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
      xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;
  &lt;head&gt;
  &lt;meta charset=&quot;UTF-8&quot; /&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot; /&gt;
  &lt;title&gt;Cadastro de Clientes&lt;/title&gt;
  &lt;link href=&quot;/webjars/bootstrap/4.5.0/css/bootstrap.min.css&quot;
      rel=&quot;stylesheet&quot;&gt;&lt;/link&gt;
  &lt;script src=&quot;/webjars/jquery/3.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;/webjars/bootstrap/4.5.0/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class=&quot;panel panel-default&quot;&gt;
          &lt;div class=&quot;panel-heading&quot;&gt;
              &lt;strong&gt;Edicao de Clientes&lt;/strong&gt;
          &lt;/div&gt;
          &lt;div class=&quot;panel-body&quot;&gt;
              &lt;form class=&quot;form-horizontal&quot; th:object=&quot;${customer}&quot;
                  th:action=&quot;@{/save}&quot; method=&quot;post&quot; style=&quot;margin: 10px&quot;&gt;
                  &lt;div class=&quot;form-group&quot;&gt;
                      &lt;fieldset&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;alert alert-danger&quot; th:if=&quot;${#fields.hasAnyErrors()}&quot;&gt;
                                  &lt;div th:each=&quot;detailedError : ${#fields.detailedErrors()}&quot;&gt;
                                      &lt;span th:text=&quot;${detailedError.message}&quot;&gt;&lt;/span&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-1&quot;&gt;
                                  &lt;input type=&quot;hidden&quot; class=&quot;form-control input-sm&quot;
                                      th:field=&quot;*{id}&quot; readonly=&quot;readonly&quot; style=&quot;display: none;&quot; /&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;col-md-1&quot;&gt;
                                  &lt;label&gt;CÓD. DO CLIENTE&lt;/label&gt; &lt;input type=&quot;text&quot;
                                      class=&quot;form-control input-sm&quot; th:field=&quot;*{customerId}&quot;
                                      readonly=&quot;readonly&quot; /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('companyName')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;RAZAO SOCIAL&lt;/label&gt; &lt;input type=&quot;text&quot;
                                      class=&quot;form-control input-sm&quot; th:field=&quot;*{companyName}&quot;
                                      autofocus=&quot;autofocus&quot; placeholder=&quot;Informe o texto&quot;
                                      maxlength=&quot;50&quot; /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('tradeName')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;NOME FANTASIA&lt;/label&gt; &lt;input type=&quot;text&quot;
                                      class=&quot;form-control input-sm&quot; th:field=&quot;*{tradeName}&quot;
                                      maxlength=&quot;150&quot; placeholder=&quot;Informe o texto&quot; /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('sectorId')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;SETOR&lt;/label&gt; &lt;input type=&quot;text&quot;
                                      class=&quot;form-control input-sm&quot; th:field=&quot;*{sectorId}&quot; /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('neighborhood')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;BAIRRO&lt;/label&gt;
                                  &lt;textarea class=&quot;form-control input-sm&quot;
                                      th:field=&quot;*{neighborhood}&quot; placeholder=&quot;Informe o texto&quot;&gt;&lt;/textarea&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('place')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;LOGRADOURO&lt;/label&gt;
                                  &lt;textarea class=&quot;form-control input-sm&quot; th:field=&quot;*{place}&quot;
                                      placeholder=&quot;Informe o texto&quot;&gt;&lt;/textarea&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('neighborhood')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;NUMERO&lt;/label&gt;
                                  &lt;textarea class=&quot;form-control input-sm&quot; th:field=&quot;*{placeId}&quot;
                                      placeholder=&quot;Informe o texto&quot;&gt;&lt;/textarea&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('city')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;CIDADE&lt;/label&gt;
                                  &lt;textarea class=&quot;form-control input-sm&quot; th:field=&quot;*{city}&quot;
                                      placeholder=&quot;Informe o texto&quot;&gt;&lt;/textarea&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('visitDay')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;DIA DE VISITA&lt;/label&gt;
                                  &lt;textarea class=&quot;form-control input-sm&quot; th:field=&quot;*{visitDay}&quot;
                                      placeholder=&quot;Informe o texto&quot;&gt;&lt;/textarea&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('region')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;REGIAO&lt;/label&gt;
                                  &lt;textarea class=&quot;form-control input-sm&quot; th:field=&quot;*{region}&quot;
                                      placeholder=&quot;Informe o texto&quot;&gt;&lt;/textarea&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('latitude')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;LATITUDE&lt;/label&gt;
                                  &lt;textarea class=&quot;form-control input-sm&quot; th:field=&quot;*{latitude}&quot;
                                      placeholder=&quot;Informe o texto&quot;&gt;&lt;/textarea&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;div class=&quot;col-md-2&quot;
                                  th:classappend=&quot;${#fields.hasErrors('longitude')}? 'has-error'&quot;&gt;
                                  &lt;label&gt;LONGITUDE&lt;/label&gt;
                                  &lt;textarea class=&quot;form-control input-sm&quot; th:field=&quot;*{longitude}&quot;
                                      placeholder=&quot;Informe o texto&quot;&gt;&lt;/textarea&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class=&quot;form-group row&quot;&gt;
                              &lt;button type=&quot;submit&quot; class=&quot;btn btn-sm btn-primary&quot;&gt;Salvar&lt;/button&gt;
                              &lt;a th:href=&quot;@{/}&quot; class=&quot;btn btn-sm btn-default&quot;&gt;Cancelar&lt;/a&gt;
                          &lt;/div&gt;
                      &lt;/fieldset&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>The method that should receive the object of formulary:</p>
  <pre><code>package com.br.aloi.planner.controller;
  
  import javax.validation.Valid;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.DeleteMapping;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.br.aloi.planner.model.Customer;
  import com.br.aloi.planner.service.CustomerService;
  
  @Controller
  public class CustomerController {
  
      @Autowired
      private CustomerService service;
  
  (...)
  
      @PostMapping(&quot;/save&quot;)
      public ModelAndView save(@Valid Customer customer, BindingResult result) {
          if (result.hasErrors()) {
              return edit(customer.getId());
          }
          service.save(customer);
          return findAll();
      }
  
  }
  </code></pre>
  <p>The objects is returning null to the <code>save</code> method on controller class. Otherwise when I select a line of the database in browser and click on 'edit', the edit page open for edition with the attributes of objects created just perfectly.</p>