0

I have a state dropdown menu which is working. I populate it with all the states and I get which state is selected. Now I need to rework it and make it available to select multiple states. I need a hint how can I get an arraylist of all the states that are multiple selected

<label for="state" class="label">State</label>
                    <select class="w-input" maxlength="256" name="state" data- 
 name="state" id="state" multiple="multiple">
                        <option th:each="state : ${states}" th:value="${state.getName()}" th:text="${state.getName()}" th:selected="${state.getName()} == ${questionnaire.getState()}"></option>
                    </select>

my controller:

model.addAttribute("states", stateService.getAllStates());
questionnaire.setState(body.get("state"));

I am looking for a way to set multiple states as an arraylist of Strings, because now I am getting only one String as a value, but not all the selected

Georgi Michev
  • 764
  • 5
  • 18
  • 37
  • Possible duplicate: https://stackoverflow.com/questions/22246759/thymeleaf-multiple-selected-on-edit – Bennett Dams Apr 23 '18 at 11:50
  • @BennettDams Thank you, I checked this one. I think i will loop and get all the states with Get request. I have problems understanding how to retreive all the states selected in a Post request and save them in an arraylist – Georgi Michev Apr 24 '18 at 07:17
  • 1
    @Georgie Michev Have a look at [Creating a form](https://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#creating-a-form) of the Thymeleaf docs. You'll see that you can map the form "response" to an URL which then should be mapped in your Rest controller via annotation. With this controller method, you can consume your data. – Bennett Dams Apr 24 '18 at 11:59

0 Answers0