Select2 and Thymeleaf integration

Viewed 24

I created a simple search bar with multiple options enabled by the Select2 library:

 <form th:action="@{/searchuser}" method="post">
   <div th:object="${searchInput}">
   <div class="input-group mb-3">
     <input type="text" th:field="*{key}" class="form-control form-control-lg" placeholder="Search Here">
     <div class="input-group-prepend">
       <span class="input-group-text" type="submit"><i class="fas fa-search"></i></span>
    </div>                
   </div>  
   
    <select class="select2-multiple-choices select2-choice"  multiple="multiple" th:field="*{parameters}">
    <option th:value="'id'" value="id"> Id</option>  
   <option th:value="'First Name'" value="First Name"> First  
      Name</option>
   <option th:value="'Middle Name'"> Middle Name</option>
   <option th:value="'Last Name'" value="Last Name"> Last Name</option>
  <option th:value="'mail'" value="Mail"> E-Mail </option>
    </select>
   </div>
 </div>               

The controller:

@RequestMapping(value = "/searchuser", method = RequestMethod.POST)
                   public ModelAndView searchUser(Locale locale, 
                  @ModelAttribute("searchInput") SearchUserDTO searchdto, 
                               BindingResult searchBindResult,                               
                               Model model) {....}

SearchUserDTO contains String key and List parameters.

I would sent to server the search key and the selected options. How can I get the selection and pass them with thymeleaf?

0 Answers
Related