title: Thymeleaf - skip table creation if the iterated list is null
body: <p>I have an html thymeleaf template where I build a table iterating over a list:</p>
  <pre><code>    &lt;table&gt;
          &lt;tr&gt;
              &lt;th&gt;Setup Name&lt;/th&gt;
              &lt;th&gt;Setup Path&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr th:each=&quot;setup : ${upgradeState.targetUpgradeSetups.setups}&quot;&gt;
              &lt;td th:text=&quot;${setup.name}&quot;/&gt;
              &lt;td th:text=&quot;${setup.path}&quot;/&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  </code></pre>
  <p>The problem is that the element <code>upgradeState.targetUpgradeSetups</code> may be <code>null</code>, so I would like to build this table only when the element is not null.</p>
  <blockquote>
  <p>Note: if the element <code>upgradeState.targetUpgradeSetups</code> is not <code>null</code>, then it's guaranteed for the list <code>setups</code> to be not null either. Hence I only need to check for the parent element.</p>
  </blockquote>
  <p>I have tried to use the <code>th:if</code> statement as follows:</p>
  <pre><code>&lt;tr th:if=${upgradeState.targetUpgradeSetups != null} th:each=&quot;setup : ${upgradeState.targetUpgradeSetups.setups}&quot;&gt;
  </code></pre>
  <p>But even like that, I still get the same exception:</p>
  <pre><code>Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'setups' cannot be found on null
      at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:213)
      at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104)
      at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:51)
      at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:406)
      at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:90)
      at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:109)
      at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:328)
      at org.thymeleaf.spring5.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:263)
      ... 74 more
  </code></pre>
  <p>I didn't manage to find a specific example/reference about Thymeleaf for such issue, could anyone please suggest the right way?</p>