title: How to extract the selected value from a datalist with Thymeleaf and Spring
body: <p>This is my html file. I did a list with all my files from DB. </p>
  
  <pre><code> &lt;div class="container"&gt;
          &lt;form action="#" th:action="@{/getFiles}" method="post"&gt;
  
          File Name: 
          &lt;input list="files" name="files" /&gt;
          &lt;datalist id="files"&gt;
              &lt;option th:each="file: ${files}" th:value=" ${file.fileName}"&gt;&lt;/option&gt;
          &lt;/datalist&gt;
          &lt;button type="submit"&gt;OK&lt;/button&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>When I select a file I want to know what file I select. 
  This is the controller. The File from post method is always empty...</p>
  
  <pre><code>@Autowired
  public FileRepository fileRepository;
  
  @GetMapping("/getFiles")
  public String fileGet(Model model) {
  
      List&lt;File&gt; files = new ArrayList&lt;&gt;();
  
      files = fileRepository.findAll();
  
      model.addAttribute("files", files);
  
      model.addAttribute("file", new File());
  
      return "filesFromDB";
  }
  
  @PostMapping("/getFiles")
  public String filePost(@ModelAttribute("file") File file, Model model) {
  
      model.addAttribute("fileName", file.getFileName());
  
      System.out.println("File: " + file.getFileName());
  
      return "resultFileDB";
  }
  </code></pre>