Using Thymeleaf's iteration constructs in order to represent a matrix as an html table

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Thymeleaf's iteration constructs in order to represent a matrix as an html table

balteo
Hello,

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:
-Monday
-Tuesday
-Wednesday
-...


Possible values for TimeSlot are:
-Morning
-Noon
-Afternoon
-Evening
-Nighttime


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).

Can anyone please help?

Regards,

J.
Reply | Threaded
Open this post in threaded view
|

Re: Using Thymeleaf's iteration constructs in order to represent a matrix as an html table

Emanuel
Administrator
Someone else recently asked about getting a matrix in HTML, and I helped them out here: http://forum.thymeleaf.org/Data-from-db-should-be-brought-to-matrix-form-td4026609.html  You might be able to find some pointers in there.

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>.
Reply | Threaded
Open this post in threaded view
|

Re: Using Thymeleaf's iteration constructs in order to represent a matrix as an html table

balteo
Thanks Emanuel.
It does make sense to use a list of list. It is much more convenient to manipulate on the thymeleaf side.
Regards,
Julien.