How to get value of id of a parent element within child element in thymeleaf?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to get value of id of a parent element within child element in thymeleaf?

paro
I am trying to bind a list in thymeleaf. Number of objects in the list is unknown. Number of parent divs are unknown, they will be added dynamically. I want to get the value of id tag of parent div and use this value as an index of arraylist within child div :

(somewhere at the beginning th:object="${student}")
<div class="parent" id="1">
   <div class="child">
      <input type="text" th:field="*{educationList[--value of id goes here, i.e. 1--].startDate}">
   </div>
   <div class="child">
      <input type="text" th:field="*{educationList[--value of id goes here, i.e. 1--].finishDate}">
   </div>
</div>
 (Next parent divs will be added dynamically)
<div class="parent" id="2">
   <div class="child">
      <input type="text" th:field="*{educationList[--value of id goes here, i.e. 2--].startDate}">
   </div>
   <div class="child">
      <input type="text" th:field="*{educationList[--value of id goes here, i.e. 2--].finishDate}">
   </div>
</div>

I want to know is it possible to get value of id, which is one with thymeleaf.
Frankly, the java logic has to be like this:
student.educationList(1, startdate)
student.educationList(1, finishdate)
student.educationList(2, startdate)
student.educationList(2, finishdate)

But as I mentioned number of objects within the list is undefined. There is a bunch of solutions in the internet with predefined objects within the list using th:each. But those are not working.

Thank you in advance