title: How to use a if statement in a div using thymeleaf?
body: <p>If I remove the div tag from the source code below my application runs with no error. But it displays an empty cell (which is correct). I just want to hide this if the cells are empty.</p>
  
  <p><strong>Thymeleaf html</strong></p>
  
  <pre><code>&lt;div th:object="${AppPortModel.Status}" th:if="${AppPortModel.Status} == 'CRITICAL'"&gt;  
  &lt;h3&gt;
  MONITORING
  &lt;/h3&gt;
  
  &lt;table id ="apCritTable"&gt;
      &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt; Status &lt;/th&gt;
          &lt;th&gt; HostName &lt;/th&gt;
          &lt;th&gt; Port Name&lt;/th&gt;
          &lt;th&gt; Port Listening Count &lt;/th&gt;
      &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
      &lt;tr th:each="AppPortModel, iterStat : ${showap}" th:if="${AppPortModel.Status == 'CRITICAL'}"&gt;
          &lt;td th:text ="${AppPortModel.Status}"&gt;&lt;/td&gt;
           &lt;td th:text="${AppPortModel.host}"&gt;${AppPortModel.host}&lt;/td&gt;
          &lt;td th:text="${AppPortModel.portOwner}"&gt;&lt;/td&gt;
           &lt;td th:text="${AppPortModel.count}"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>AppPortModel</strong></p>
  
  <pre><code>public class AppPortModel implements Comparable {
  private String Status;
  private String host;
  private String portName;
  private String plCount;
  
  //getters and setters
  
  @Override int compareTo(Object o) {
  return //stuff
   }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>@Controller
  public class IndexController {
  
  @RequestMapping(value = "/", method = RequestMethod.GET)
  public ModelAndView getdata() throws IOException {
  ModelAndView model = new ModelAndView("index");
          model.addObject("showap", apList);
              return model;
  }
  </code></pre>
  
  <p><strong>AppPortList</strong></p>
  
  <pre><code>@Component
      public class AppPortList {      
  
     @Value("#{'$APP_SERVERS_PORT}'.split('@!')}")
     private String[] apServerArray;
     @Value("#{'${APP_SERVER_MONITORING_LIST}'.split('@!')}")
     private String[] appServerPortsList;
  @PostConstruct
      public List&lt;AppPortModel&gt; getAppPortList() {
  
      final int MYTHREADS = 80;
      ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS);
  
      ApplicationPort.resetData();
  
      try {
  
          for (int z = 0; z &lt; apServerArray.length; z++) {    
  
              String apServer = apServerArray[z];
              String[] portListArray=appServerPortsList[z].split(",");
              ApplicationPort apWorker = new ApplicationPort(apServer, portListArray);
              executor.execute(apWorker);
          }   
          } catch(ArrayIndexOutOfBoundsException e) {
                  System.out.println("ArrayIndexOutOfBoundsException in AppPortList");
              }
              finally {
              executor.shutdown();
  
              while (!executor.isTerminated()) {
              }               
              logger.info("\nFinished all threads in App Port. ");    
              }
              return ApplicationPort.getData();               
          }     
  </code></pre>
  
  <p><strong>Snippet of Class App</strong></p>
  
  <pre><code>static List&lt;AppPortModel&gt; apData = new ArrayList&lt;AppPortModel&gt;();
  
  public static List&lt;AppPortModel&gt; getData() {
      return apData;
  }
  
  public static void setData(List&lt;AppPortModel&gt; apData) {
      ApplicationPort.apData = apData;
  }
  
  public static void resetData(){
      apData = new ArrayList&lt;AppPortModel&gt;();
  }
  
  public ApplicationPort(String apServer, String[] portListArray) {
  this.apServer = apServer;   
  this.portListArray = portListArray;
  
  }
  </code></pre>
  
  <p>This table will populate if AppPortModel.Status is CRITICAL. I am trying to hide this table if there is no values in this table. If I just have a regular div tag my code will run but I will have a awkward head and table row heads on my page with empty cells.</p>
  
  <p><strong>Attempt</strong></p>
  
  <p>I tried adding some th logic into my div tag, but I receive an null error.</p>
  
  <pre><code> &lt;div th:object="${AppPortModel.Status}" th:if="${AppPortModel.Status == 'CRITICAL'}"&gt;  
  </code></pre>
  
  <p><strong>Attempt 2</strong></p>
  
  <pre><code>&lt;div th:if="${Status} == 'CRITICAL'"&gt;  
  </code></pre>
  
  <p>This script would hide my div tag. Even if I have Status = to CRITICAL it would still hide the table.</p>