BAEL-5413: populate a drop down with a list (#11947)
This commit is contained in:
parent
ac99726577
commit
c6e2b905f5
@ -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<String> options = new ArrayList<String>();
|
||||||
|
options.add("option 1");
|
||||||
|
options.add("option 2");
|
||||||
|
options.add("option 3");
|
||||||
|
options.add("option 4");
|
||||||
|
model.addAttribute("options", options);
|
||||||
|
return "dropDownList/dropDownList.html";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Populate a drop down with a list using thymeleaf</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Populate a drop down with a list using thymeleaf</h1>
|
||||||
|
<select class="form-control" id="dropDownList">
|
||||||
|
<option value="0">select option</option>
|
||||||
|
<option th:each="option : ${options}" th:value="${option}" th:text="${option}"></option>
|
||||||
|
</select>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user