title: Get list within a list using Thymeleaf
body: <p>I have two tables one names "State" another named "City"</p>
  
  <p>My city model</p>
  
  <pre><code>@Entity
  @Table(name = "city")
  public class City implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;
      private String city;
      @ManyToOne
      private State state;
  
      public City() {
      }
  
      public Integer getId() {
          return this.id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public String getCity() {
          return this.city;
      }
  
      public void setCity(String city) {
          this.city = city;
      }
  
      public State getState() {
          return this.state;
      }
  
      public void setState(State state) {
          this.state = state;
      }
  }
  </code></pre>
  
  <p>my state model</p>
  
  <pre><code>@Entity
  @Table(name = "state")
  public class State implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;
  
      private String state;
  
      @OneToMany(mappedBy = "state")
      private List&lt;City&gt; cities;
  
      public State() {
      }
  
      public Integer getId() {
          return this.id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public String getState() {
          return this.state;
      }
  
      public void setState(String state) {
          this.state = state;
      }
  
      public List&lt;City&gt; getCities() {
          return this.cities;
      }
  
      public void setCities(List&lt;City&gt; cities) {
          this.cities = cities;
      }
  
      public City addCity(City city) {
          getCities().add(city);
          city.setState(this);
  
          return city;
      }
  
      public City removeCity(City city) {
          getCities().remove(city);
          city.setState(null);
  
          return city;
      }
  }
  </code></pre>
  
  <p>my CityRepository</p>
  
  <pre><code>public interface CityRepository extends CrudRepository&lt;City, Long&gt; {
      List&lt;City&gt; findByState(String city);
  }
  </code></pre>
  
  <p>my StateRepository</p>
  
  <pre><code>public interface StateRepository extends CrudRepository&lt;State, Long&gt; {
      List&lt;State&gt; findByState(String state);
  }
  </code></pre>
  
  <p>my controller</p>
  
  <pre><code>@Controller
  public class IndexController {
      @Autowired
      StateRepository stateRepository;
      @Autowired
      CityRepository cityRepository;
  
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public String index(Model model) {
          model.addAttribute("title", "");
  
          Iterable&lt;State&gt; stateIterable = stateRepository.findAll();
  
          for (State state : stateIterable) {
              System.out.println(state.getState());
          }
  
          model.addAttribute("stateIterable", stateIterable);
  
          return "index";
      }
  }
  </code></pre>
  
  <p>and the relevant code for Theymeleaf</p>
  
  <pre><code>&lt;div class="col-md-4"&gt;
      &lt;div class="panel-group" id="panel-790692"&gt;
          &lt;th:block th:each="state : ${stateIterable}"&gt;
              &lt;div class="panel panel-default"&gt;
                  &lt;div class="panel-heading"&gt;
                      &lt;a class="panel-title" data-toggle="collapse"
                          data-parent="#panel-790692"
                          th:href="|#panel-element-${#strings.replace(state,' ','-')}|"
                          th:text="${state.state}"&gt;State Name&lt;/a&gt;
                  &lt;/div&gt;
                  &lt;th:block th:each="city : ${state.getCities}"&gt;
                      &lt;div th:id="|panel-element-${#strings.replace(state,' ','-')}|"
                          class="panel-collapse collapse in"&gt;
                          &lt;div class="panel-body" th:text="city.city"&gt;&lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/th:block&gt;
              &lt;/div&gt;
  
          &lt;/th:block&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Right now I am getting this error</p>
  
  <p>"Property or field 'getCities' cannot be found on object"</p>
  
  <p>Is it possible to get the cities and loop through the cities using Themeleaf? If so how can it be done?</p>