Reputation: 2748
How to apply th:each on th:switch for values from Enum in following case?
public enum Framework {
ABC0(0, "Name0"),
ABC1(1, "Name1"),
ABC2(2, "Name2"),
ABC3(3, "Name3");
public int id;
public String name;
private Framework (int id, String name){
this.id = id;
this.name = name;
}
}
and in model class I have a field:
private int frameworkId;
Thank you
Upvotes: 1
Views: 660
Reputation: 2748
I figured it out - it is quite simple.
I passed values of Framework to form in Controller class:
model.addAttribute("frameworks", Framework.values());
and then:
<span class="cls">Framework:</span>
<span th:switch="${item.frameworkId}">
<span th:each="fw : ${frameworks}">
<span th:case="${fw.id}" th:text="${fw.name}"></span>
</span>
</span>
Upvotes: 1