Custom Tag implementation issue
Posted
by Appps
on Stack Overflow
See other posts from Stack Overflow
or by Appps
Published on 2010-03-31T07:11:01Z
Indexed on
2010/03/31
7:13 UTC
Read the original article
Hit count: 316
customtags
I have a custom tag as follows. repeat and heading tag have doAfterBody method implemented.
<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
}
The order in which SOP are printed is 1) Setter method of csajsp:repeat is called. 2) 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. Thanks in advance.
© Stack Overflow or respective owner