Continuous numeration of nested loop items in Thymeleaf

What you trying to achieve is to update a local variable and have the new value be visible in a scope wider than where the update was made. That's why it contradicts with th:with definition. I think you can't avoid making some server side tweaking for example providing some flatter view of your structure as you suggested.

On the other side, a quick solution, (assuming you are not strictly towards using a table) it might be trying an ordered list while using th:blocks for the enclosing department :

<ol>
  <!--/*/ <th:block th:each="dept : ${departmentList} "> /*/-->

   <li th:each="emp : dept.employees" th:text="|${emp.name} from ${dept.name}|"></li>

  <!--/*/ </th:block> /*/-->
</ol>  

Tags:

Java

Thymeleaf