Answer the question
In order to leave comments, you need to log in
How to create a scrollbar on thymeleaf that returns a string?
Hello, if I want to fill in some fields on the object mapped to the page, then it will look something like this:
<form th:action="@{'/plantEdit/'+${boxId}}"
th:object="${plant}" method="POST">
<input th:type="hidden" name="id" th:field="${plant.id}" />
Plant name:
<input type="text" th:field="*{plantName}" />
<br/>
<input type="submit" value="Create" />
<a href="#" th:href="@{/}" role="button">Cancel</a>
</form>
@RequestMapping(value = {"/plantEdit/{boxId}", "/plantEdit/{boxId}/{id}"}, method = RequestMethod.GET)
public String growBoxesEditForm(Model model,
@PathVariable(name = "boxId") Long boxId,
@PathVariable(required = false, name = "id") Long id) throws ResourceNotFoundException {
logger.info("now we observe plant with id : " + id);
if(id != null){
model.addAttribute("plant", plantService.findById(id));
}else {
model.addAttribute("plant", new Plant());
}
model.addAttribute("boxId", boxId);
return "plantEdit";
}
@RequestMapping(value = "/plantEdit/{boxId}", method = RequestMethod.POST)
public String growBoxEditForm(Model model, Plant plant,
@PathVariable(name = "boxId") Long boxId) throws ResourceNotFoundException {
GrowBox box = growBoxService.findById(boxId);
plant.setResponsibleGrowBox(box);
plantService.savePlant(plant);
model.addAttribute("plants", plantService.findByBoxId(boxId));
return "showPlants";
}
Answer the question
In order to leave comments, you need to log in
To be honest, I didn't quite understand what you mean by "scrollbar" in this context...
Based on this text:
Let's say you want to create a dropdown list with a scrollbar where the user can select data.
To implement it, you need to do the following:
1) implement a method that returns a List or an array of strings with plant names. (in Repository).
2) In a GET request, when opening a page, model.addAttribute("plants", repo.getPlants())
pass this information through Model ( ).
3) then it remains to wrap the whole thing nicely in a dropdown list.
https://getbootstrap.com/docs/4.3/components/dropdowns/
You can store possible plants as in a database (if frequent additions and deletions of varieties are expected) or stored as an Enum.
depends on what you choose. In a controller method, you can take an object and save it, you can take an enum and save it, you can take a String and use String.valueOf(myString) to save the enum, and so on.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question