title: th:disabled objects in Thymeleaf
body: <p>I have a basic SpringBoot 2.0.5.RELEASE app. Using Spring Initializer, JPA, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file.</p>
  
  <p>I have a select object that is readonly,</p>
  
  <pre><code>&lt;select id="selectInvoiceId" th:field="*{invoice}" th:disabled="${resto.id != null}" &gt;
      &lt;option value="0"&gt;PLEASE SELECT AN INVOICE&lt;/option&gt;
      &lt;option th:each="invoice : ${invoices}" 
              th:value="${invoice.id}" 
              th:text="${invoice.symbol}"&gt;
      &lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>in the controller I have</p>
  
  <pre><code>@RequestMapping(value = { "/save" }, method = RequestMethod.POST)
  public String saveWallet(@Valid @ModelAttribute("wallet") WalletPayload walletPayload, 
      BindingResult bindingResult) {
      ..
  }
  </code></pre>
  
  <p>and in the WalletPayload object I have:</p>
  
  <pre><code>@NotNull
  private Invoice invoice;
  </code></pre>
  
  <p>then I got always an error in the validation because invoice is null, I would like to know if there is a workaround for the readonly objects</p>
  
  <p>I've tried this, but I have still the error:</p>
  
  <pre><code>@RequestMapping(value = { "/save" }, method = RequestMethod.POST)
      public String saveWallet(@Valid @ModelAttribute("wallet") WalletPayload walletPayload,
              BindingResult bindingResult) {
  
  
          LOG.debug("WalletPayload walletPayload [ " + walletPayload + " ]");
  
          if (walletPayload.getId() != null) {
              Invoice fakeInvoine = new Invoice("fake-inv");
              fakeInvoice.setId((long)-1);
              walletPayload.setInvoice(fakeInvoice);
          }
  
  
          if (bindingResult.hasErrors()) {
              return serverContextPath + WALLET_LIST_VIEW_NAME;
          }
  </code></pre>
  
  <p>I also tried to use readonly, but it does not appear as an option on the select object</p>
  
  <p><a href="https://i.stack.imgur.com/LOhjG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LOhjG.png" alt="enter image description here"></a></p>