Hello,
I have a newbie question, I'm trying to create JSP tag with a body.
My tag inside of the JSP page looks looks like this:
<mytag:test>
Printing: <%= test %> <br>
</mytag:test>
I'm trying to place value for test.
But for example every time I'm getting:
Printing: null
Printing: test tag
Printing: test tag
It almost looks like pageContext.setAttribute method is called before
doAfterBody() method
is executed by the container.
I was was able to find work around by placing the same code that is in
doAfterBody() method inside of doIntBody().
public void doInitBody() throws JspException{
if(number ==0){
return SKIP_BODY;
}
else{
number--;
pageContext.setAttribute("test","test tag");
return EVAL_BODY_TAG;
}
}
I'm just trying to find out if there is any other way of dealing with
this type of issue.
Thanks for help.
Robert
Here is code for my tag without doIntBody() method.
package webmessanger;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import javax.servlet.*;
import java.io.Writer;
import java.util.*;
import java.io.*;
public class TestTag extends BodyTagSupport {
int number;
public int doEndTag() throws JspException{
try{
bodyContent.writeOut(bodyContent.getEnclosingWriter());
}
catch(Exception e){
System.err.println(e);
}
return EVAL_PAGE;
}
public int doStartTag() throws JspException {
number = 2;
return EVAL_BODY_TAG;
}
public int doAfterBody() throws JspException{
if(number ==0){
return SKIP_BODY;
}
else{
number--;
pageContext.setAttribute("test","test tag");
return EVAL_BODY_TAG;
}
}
}
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com