spring boot / thymeleaf nested loop object access
<p>I am using Spring Boot and Thymeleaf to create a single landing page for
my application. For this, I need to render a List of Host objects that all
contain a Container.
Here is the relevant code:</p>

<pre><code>public class Container {
    private String name;
    private String baseUrl;
    private String status;

    public Container(String name, String baseUrl, String status) {
        this.name = name;
        this.baseUrl = baseUrl;
        this.status = status;
    }

    public String getName() { return name; }
    public String getBaseUrl() { return baseUrl; }
    public String getStatus() { return status; }
}

public class Host {
    private HashMap&lt;String, Container&gt; containers;
    ....
    public List&lt;Container&gt; getContainers() {
         return containers.values();
    }
}

@RequestMapping("/")
public class IndexController {
      @RequestMapping("/")
      public String getIndex(Model model) {
          model.addAttribute("hosts", hostRepository.getAllServers());
          return "index";
      }
}
</code></pre>

<p>Now I want to iterate over all servers and display the information about each Container in a table.
My Thymeleaf template looks like this:</p>

<pre><code>&lt;div class="panel panel-default" th:each="host : ${hosts}"&gt;
            &lt;div class="panel-heading"&gt;
                &lt;b th:text="${host.name}"&gt;Host X&lt;/b&gt;
                &lt;div class="panel-body"&gt;
                    &lt;table class="table"&gt;
                        &lt;thead&gt;
                            &lt;tr&gt;
                                &lt;th&gt;Name&lt;/th&gt;
                                &lt;th&gt;URL&lt;/th&gt;
                                &lt;th&gt;Status&lt;/th&gt;
                            &lt;/tr&gt;
                        &lt;/thead&gt;
                        &lt;tbody&gt;
                            &lt;tr th:each="container : ${host.getContainers()}"&gt;
           &lt;!-- HERE IS THE PROBLEM --&gt;
                                &lt;td th:text="${container.name}"&gt;Service1&lt;/td&gt;
                                &lt;td th:text="${container.baseUrl}"&gt;domain.com/api/url&lt;/td&gt;
                                &lt;td th:text="${container.status}"&gt;RUNNING&lt;/td&gt;
           &lt;!-- HERE ENDS THE PROBLEM --&gt;
                            &lt;/tr&gt;
                        &lt;/tbody&gt;
                    &lt;/table&gt;
                &lt;/div&gt;
            &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>My problem is the part where is access the container's properties (marked by the commentary).
Every time I get a SpringEL Exception. If I remove the <code>th:text="${container.xy}"</code> and replaces it with <code>th:text="${container}</code> a String version of the container is shown so I have access to the object and the loop it working properly. I also tried to replace the field access with getters (e.g. <code>getStatus()</code>) but it also does not work. </p>

<p>Thanks for your help. If you need more information, feel free to ask.</p>

<p>Setup:</p>

<ul>
<li>Java 8</li>
<li>Spring Boot Starter Web</li>
<li>Thymeleaf </li>
</ul>

<p><strong>edit</strong>: The exception thrown is: <code>nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "container.name" (index:35)</code> where index:35 is the first problematic line.</p>

<p>The toString() output when using <code>${container}</code> is <code>jenkins=com.my.app.Container@7552c269</code> and jenkins is the <code>name</code> attribute of the Container instance.</p>

<p><strong>Solution</strong> It seemed that the nested loop was iterating over a Map instead of a List. Changing <code>${container.xy}</code> to <code>${container.getValue().xy}</code> solved the problem.</p>