title: Java Tapestry: Clearing a count value after a t:if test
body: <p>I am printing the first 12 elements of a Comments array. After 12 have been printed, a "More" link is printed. I am doing this using a COMMENT_COUNT int, and iterating it on each comment printed. I want to return the value of COMMENT_COUNT to 0 after the "More" link is printed.</p>
  
  <p>I have left my current hack in place, in which I just call ${clearCount()} after printing the "More" link. What now happens is that 12 comments are printed, then a "MORE" link is printed, and then the boolean value "true" is printed.</p>
  
  <p>I am guessing there is a much, much better way to do this. I am looking for a better way to call ${clearCount()}, or a better way to set COMMENT_COUNT to 0 after printing the "More" link.</p>
  
  <p>--- EDITED TO ADD ----</p>
  
  <p>An additional requirement is that the COMMENT_COUNT counts only the first 12 visible comments (comments may be visible or not depending on the user), so have some ugly nested if statements: </p>
  
  <p>.tml: </p>
  
  <pre><code>&lt;t:loop source="currentCategoryTextmedium.commentArraySorted" value="currentComment"&gt;
   //test if the current comment should be visible
   &lt;t:if test="isCurrentCommentVisible()"&gt;         
      &lt;t:if test="isCommentLessThan12()"&gt;
      //print first 12 visible comments
          &lt;span&gt;
              &lt;a blah blah&gt;${currentComment.blahblah}&lt;/a&gt;
          &lt;/span&gt;
      &lt;/t:if&gt;     
    &lt;/t:if&gt;                                                           
  &lt;/t:loop&gt;
  
  &lt;t:if test="isCommentMoreThan12()"&gt;
      //print one More link
      &lt;span&gt;
          &lt;a "blah blah"&gt;MORE&lt;/a&gt;
      &lt;/span&gt;
  &lt;/t:if&gt;
  
  //Clear the COMMENT_COUNT so that the right number of comments print on another element
  ${clearCount()}
  </code></pre>
  
  <p>java:</p>
  
  <pre><code>public int COMMENT_COUNT; 
  
  public boolean isCommentLessThan12() {
      if (COMMENT_COUNT &lt; 12) {
          COMMENT_COUNT++;
          return true;
      }
      else {
      return false;
      }
  }
  public boolean isCommentMoreThan12() {
      COMMENT_COUNT++;
      if (COMMENT_COUNT &gt; 12) {
          return true;
      }
      else {
      return false;
      }
  }
  
  public boolean clearCount() {
      COMMENT_COUNT= 0;
      return true;
  }
  </code></pre>