0

I have three Entities User, Albums and Photo, In User l have a collection of Album, in Album l have a collection of photos. Now in my user.htlm i would like to know foreach user the number of album and the number of photo. I can get the number of album by using

<td th:text="${#lists.size(u.albums)}"></td>

How can l get the number of photo? Thanks for your answer

Syllaba Abou Ndiaye
  • 213
  • 1
  • 7
  • 21

1 Answers1

1

Try using below code.

<td th:text="${#lists.size(u.albums[0].photo)}"></td>

Note : You can replace zero with index or counter value during iteration.

Alien
  • 15,141
  • 6
  • 37
  • 57
  • thanks you Alien it's work. However when i try to replace zero with index have an error "The collection has 1 elements, index '1' is invalid – Syllaba Abou Ndiaye Jul 10 '18 at 10:18
  • Simply add an th:if condition if the u.albums can have zero elements...or add question mark before ...refere this https://stackoverflow.com/questions/20636456/using-thymeleaf-when-the-value-is-null – Alien Jul 10 '18 at 10:25
  • now the problem is how can i replace the zero with correct value i already try to do after i use status to replace zero by using this code ` ` but i have and error because currently there is 1 element in albums so i can't do albums[1] – Syllaba Abou Ndiaye Jul 10 '18 at 10:39