'Get and display item from list<Item> in Thymeleaf template
I have an HTML5 page using Thymeleaf templates.
The Java controller has a ModelAttribute of a MyData which is a List of MyItems via a service class.
@Controller
public class MyController {
private final MyService myService;
@Autowired
public MyController(MyService myService) {
this.myService = myService;
}
@ModelAttribute
public MyData myData() {
return myService.getMyData();
}
}
I don't want to loop through the data in a for:each loop and display the data as I am not displaying it all in a table. There are many examples of this around.
I need at various points in my form to find particular items from the list and display some fields from the located list item.
The item should be located using 2 values <th:thisItem = getMyItem(param1,param2)> and then reference thisItem.fieldX to display the data on the form.
I know I have the list referenced via the ModelAttribute as myData to the form, but how can I find a specific item.
Thanks
ps. I don't want to use jsp pages
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
