Using Thymeleaf's iteration constructs in order to represent a matrix as an html table
I am running into a Thymeleaf puzzler and I wondered if someone would be willing to help me with it...
Basically, my domain model has a sort of availability matrix with days of the week (Day) and time slots (TimeSlot).
Possible values for Day are:
Possible values for TimeSlot are:
I therefore have a JPA entity called DayToTimeSlot that has both fields: Day and TimeSlot.
I would like to display this matrix in a html table with days as columns and time slots as rows and all combinations represented.
For example, the cell in the first column and the first row, I would have Monday, Morning. Then in the first column second row, I would have Monday, Noon. And so on.
I am really not sure how to achieve that bearing in mind I have a collection of the DayToTimeSlot entity. What makes it more tricky, is that the first line of the table needs to contain the TimeSlot label (e.g. Morning).
It got a whole lot easier when we were able to have the model match the intended output, so that meant turning it into a 2D array (or list of lists), then just using nested th:each processors in the <tr>, then the <td>.