Java Tapestry: Clearing a count value after a t:loop
I am printing the first 12 elements of a Comments array. After 12 have
been printed, a "More" link is printed. I am doing 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. How can I do this?
I have left my current hack in place, in which I just call ${clearCount()}
after printing the "More" link (right now it spits "true" out into the
template). 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.
.tml:
<t:loop source="currentCategoryTextmedium.commentArraySorted"
value="currentComment">
<t:if test="isCommentLessThan12()">
<span>
<a blah blah>${currentComment.blahblah}</a>
</span>
</t:if>
</t:loop>
<t:if test="isCommentMoreThan12()">
<span>
<a "blah blah">MORE</a>
</span>
</t:if>
${clearCount()}
java:
public int COMMENT_COUNT;
public boolean isCommentLessThan12() {
if (COMMENT_COUNT < 12) {
COMMENT_COUNT++;
return true;
}
else {
return false;
}
}
public boolean isCommentMoreThan12() {
COMMENT_COUNT++;
if (COMMENT_COUNT > 12) {
return true;
}
else {
return false;
}
}
public boolean clearCount() {
COMMENT_COUNT= 0;
return true;
}
No comments:
Post a Comment