I have customs tags as follows. repeat and heading tag have doAfterBody
method implemented.Both of them extends BodyTagSupport class
<csajsp:repeat reps="5">
<LI>
<csajsp:heading bgColor="BLACK">
White on Black Heading
</csajsp:heading>
</LI>
</csajsp:repeat>
Repeat tag Class
public void setReps(String repeats) {
System.out.println("TESTING"+repeats);
//sets the reps variable.
}
public int doAfterBody() {
System.out.println("Inside repeate tag"+reps);
if (reps-- >= 1) {
BodyContent body = getBodyContent();
try {
JspWriter out = body.getEnclosingWriter();
System.out.println("BODY"+body.getString());
out.println(body.getString());
body.clearBody(); // Clear for next evaluation
} catch(IOException ioe) {
System.out.println("Error in RepeatTag: " + ioe);
}
return(EVAL_BODY_TAG);
} else {
return(SKIP_BODY);
}
}
Class of Heading tag
public int doAfterBody()
{
System.out.println("inside heading tag");
BodyContent body = getBodyContent();
System.out.println(body.getString());
try {
JspWriter out = body.getEnclosingWriter();
out.print("NEW TEXT");
} catch(IOException ioe) {
System.out.println("Error in FilterTag: " + ioe);
}
// SKIP_BODY means I'm done. If I wanted to evaluate
// and handle the body again, I'd return EVAL_BODY_TAG.
return(SKIP_BODY);
}
public int doEndTag() {
try {
JspWriter out = pageContext.getOut();
out.print("NEW TEXT 2");
} catch(IOException ioe) {
System.out.println("Error in HeadingTag: " + ioe);
}
return(EVAL_PAGE); // Continue with rest of JSP page
}
Custom tag tld file is
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>csajsp</shortname>
<uri></uri>
<tag>
<name>heading</name>
<tagclass>com.test.tags.HeadingTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>bgColor</name>
<required>true</required> <!-- bgColor is required -->
</attribute>
</tag>
<tag>
<name>repeat</name>
<tagclass>com.test.tags.RepeatTag</tagclass>
<info>Repeats body the specified number of times.</info>
<bodycontent>JSP</bodycontent>
<attribute>
<name>reps</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
The order in which SOP are printed is
- Setter method of csajsp:repeat is called.
- White on Black Heading is printed. ie doAfterBody of csajsp:heading tag is called.
I don't know why it is not calling doAfterBody
of csajsp:repeat
tag.
Please help me to understand this.