title: How to use input radio button with thymeleaf and Spring MVC
body: <p>I would like to get a destination address from a input radio button list. The DestinationAddress class is the following:</p>
  
  <pre><code>public class DestinationAddress {
  
      private Integer destinationAddressId;
  
      private String name;
  
      private Location location;
  
      private User owner;
  
  
      public DestinationAddress(String name, Location location, User owner) {
          this.name = name;
          this.location = location;
          this.owner = owner;
      }
  
      public DestinationAddress() {
      }
  // getter and setter
  
  }
  </code></pre>
  
  <p>The controller who handles the get and post is the following:</p>
  
  <pre><code>@PreAuthorize("hasRole('USER')")
      @GetMapping(value = "/select-address")
      public String selectAddress(Principal principal, Model model) {
          List&lt;DestinationAddress&gt; addresses = destinationAddressService.getAllByUsername(principal.getName());
          model.addAttribute("destinationAddresses", addresses);
          model.addAttribute("destinationAddress", new DestinationAddress());
          return "purchase/select-address";
      }
  
  
      @PreAuthorize("hasRole('USER')")
      @PostMapping(value = "/select-address")
      public String selectAddress(@ModelAttribute DestinationAddress destinationAddress, Principal principal) {
          Purchase purchase = purchaseService.addPurchase(principal.getName(), destinationAddress);
          return "redirect:/purchases/pay/" + purchase.getPurchaseId();
      }
  </code></pre>
  
  <p>And the html page is the following:</p>
  
  <pre><code>&lt;form th:object="${destinationAddress}" method="post"&gt;
      &lt;fieldset&gt;
      &lt;legend&gt;Your addresses&lt;/legend&gt;
      &lt;ul&gt;
          &lt;li th:each="destinationAddress : ${destinationAddresses}"&gt;
              &lt;input type="radio" th:field="*{destinationAddressId}" th:value="${destinationAddress.destinationAddressId}" /&gt;
              &lt;label th:for="${#ids.prev('destinationAddress.destinationAddressId')}" th:text="${destinationAddress}"&gt;&lt;/label&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/fieldset&gt;
  &lt;p&gt;&lt;input type="submit" value="Submit" /&gt; &lt;input type="reset" value="Reset" /&gt;&lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The error message is the following:</p>
  
  <pre><code>java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'destinationAddressId' available as request attribute
  </code></pre>
  
  <p>I don't know what's the problem here. I don't know which type will the form return to the controller. So I don't know which variable pass to the model and which one to get from the post controller method. Integer or DestinationAddress? I cannot find anything googling it, just small pieces of code without any explanations. Any suggestions? </p>