title: How to display all possible enum values in a dropdown list using Spring and Thymeleaf?
body: <p>I have a domain object that has an enum property and I want to display a dropdown list with all possible enum values in the form for this object. Imagine the following object:</p>
  
  <pre><code>public class Ticket {
  
    private Long id;
  
    private String title;
  
    private State state;
  
    // Getters &amp; setters
  
    public static enum State {
      OPEN, IN_WORK, FINISHED
    }
  
  }
  </code></pre>
  
  <p>In my controller I have a method that renders a form for this object:</p>
  
  <pre><code>@RequestMapping("/tickets/new")
  public String showNewTicketForm(@ModelAttribute Ticket ticket) {
    return "tickets/new";
  }
  </code></pre>
  
  <p>The template looks like this:</p>
  
  <pre><code>&lt;form th:action="@{/tickets}" method="post" th:object="${ticket}"&gt;
    &lt;input type="text" th:field="*{title}" /&gt;
    &lt;select&gt;&lt;/select&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Later it should be transformed to something like this:</p>
  
  <pre><code>&lt;form action="/tickets" method="post"&gt;
    &lt;input type="text" name="title" /&gt;
    &lt;select name="state"&gt;
      &lt;option&gt;OPEN&lt;/option&gt;
      &lt;option&gt;IN_WORK&lt;/option&gt;
      &lt;option&gt;FINISHED&lt;/option&gt;
    &lt;/select&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>How can I create the select tag? The selected value should also be mapped to the ticket automatically so that I can do something like this in the controller:</p>
  
  <pre><code>@RequestMapping(value = "/tickets", method = RequestMethod.POST)
  public String createTicket(@Valid Ticket ticket) {
    service.createTicket(ticket);
  
    return "redirect:/tickets";
  }
  </code></pre>