From c6e2b905f5010c22fc21198433be3c26233e4734 Mon Sep 17 00:00:00 2001 From: ACHRAF TAITAI <43656331+achraftt@users.noreply.github.com> Date: Sun, 20 Mar 2022 08:45:32 +0100 Subject: [PATCH] BAEL-5413: populate a drop down with a list (#11947) --- .../dropDownList/DropDownListController.java | 24 +++++++++++++++++++ .../templates/dropDownList/dropDownList.html | 14 +++++++++++ 2 files changed, 38 insertions(+) create mode 100644 spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/dropDownList/DropDownListController.java create mode 100644 spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/dropDownList/dropDownList.html diff --git a/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/dropDownList/DropDownListController.java b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/dropDownList/DropDownListController.java new file mode 100644 index 0000000000..ba1f1b0a49 --- /dev/null +++ b/spring-web-modules/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/dropDownList/DropDownListController.java @@ -0,0 +1,24 @@ +package com.baeldung.thymeleaf.dropDownList; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.ArrayList; +import java.util.List; + +@Controller +public class DropDownListController { + + @RequestMapping(value = "/populateDropDownList", method = RequestMethod.GET) public String populateList(Model model) { + List options = new ArrayList(); + options.add("option 1"); + options.add("option 2"); + options.add("option 3"); + options.add("option 4"); + model.addAttribute("options", options); + return "dropDownList/dropDownList.html"; + } + +} diff --git a/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/dropDownList/dropDownList.html b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/dropDownList/dropDownList.html new file mode 100644 index 0000000000..cc2c504b32 --- /dev/null +++ b/spring-web-modules/spring-thymeleaf-3/src/main/resources/templates/dropDownList/dropDownList.html @@ -0,0 +1,14 @@ + + + +Populate a drop down with a list using thymeleaf + + +

Populate a drop down with a list using thymeleaf

+ + +