This is my code:
My classes:
<code>public class Persons {
List<Student> students;
}
</code>
<code>public class Persons {
List<Student> students;
}
</code>
public class Persons {
List<Student> students;
}
<code>public class Student {
List<String> role;
}
</code>
<code>public class Student {
List<String> role;
}
</code>
public class Student {
List<String> role;
}
In thymeleaf:
<code><select id="role" tabindex="16" class="form-select input-widget custom-size" th:field="*{students[0].role[0]}">
<option value="1">Mathematician</option>
<option value="2">Economist</option>
</select>
</code>
<code><select id="role" tabindex="16" class="form-select input-widget custom-size" th:field="*{students[0].role[0]}">
<option value="1">Mathematician</option>
<option value="2">Economist</option>
</select>
</code>
<select id="role" tabindex="16" class="form-select input-widget custom-size" th:field="*{students[0].role[0]}">
<option value="1">Mathematician</option>
<option value="2">Economist</option>
</select>
It means that every student can have multiple roles. The issue is that the program iterate only the first array (i.e. students[1].role[0], students[2].role[0]), but not the second array. Is there a way to control which array will iterated? I want that in this select tag only the second array is iterated.
I tried the above example, but only the first array is iterated.
It should look something like this:
<code><th:block th:each="student, i: *{students}">
<th:block th:each="role, j: ${student.role}">
<select tabindex="16" class="form-select input-widget custom-size" th:field="*{students[__${i.index}__].role[__${j.index}__]}">
<option value="1">Mathematician</option>
<option value="2">Economist</option>
</select>
</th:block>
</th:block>
</code>
<code><th:block th:each="student, i: *{students}">
<th:block th:each="role, j: ${student.role}">
<select tabindex="16" class="form-select input-widget custom-size" th:field="*{students[__${i.index}__].role[__${j.index}__]}">
<option value="1">Mathematician</option>
<option value="2">Economist</option>
</select>
</th:block>
</th:block>
</code>
<th:block th:each="student, i: *{students}">
<th:block th:each="role, j: ${student.role}">
<select tabindex="16" class="form-select input-widget custom-size" th:field="*{students[__${i.index}__].role[__${j.index}__]}">
<option value="1">Mathematician</option>
<option value="2">Economist</option>
</select>
</th:block>
</th:block>
1