File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested bean: doEngTag() not invoked

 
Tiffiny Yang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning how nested beans works. The code I am running is fine except the doEngTag() are NOT invoked in any of the tag handlers.

-- jsp file --
<%@ taglib uri="outerTagExample" prefix="ot" %>
<%@ taglib uri="getParentTag" prefix="gpt" %>
<html><head>
<ot uterTag count="99">
<gpt:getParentTag/>
</ot uterTag>
</body></html>
------------

--- OuterTag.java
package coreservlets.tags;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import java.io.*;

public class OuterTag extends TagSupport
{
private int count;
JspWriter out ;
public int doStartTag()
{
out = pageContext.getOut();
try{ out.print("Count==>"+count); }
catch(Exception e){ }
return EVAL_BODY_INCLUDE;
}
public void setCount(int count) {this.count = count; }
public int getCount() {return this.count; }
public int doAfterBody() {return EVAL_BODY_INCLUDE; }
public int doEngTag() throws JspException, IOException
{
out.print("OuterTag class of doEngTag() Done.");
System.out.println("OuterTag class , doEngTag() -- Done.");
return SKIP_PAGE;
}
}
-- GetParentTag.java --
package coreservlets.tags;
import java.io.IOException;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
public class GetParentTag extends TagSupport
{
JspWriter out;
public int doStartTag()
{
OuterTag parent = (OuterTag)this.getParent();
JspWriter out = pageContext.getOut();
try{ out.print("Count value of parent ="+parent.getCount());
}catch(Exception e){ }
return EVAL_BODY_INCLUDE;
}
public int doAfterBody() { return EVAL_BODY_INCLUDE; }
public int doEngTag() throws JspException, IOException
{
out.print(" Done.");
System.out.println("doEngTag() in GetParentTag ");
return SKIP_PAGE;
}
}

---
Why doEngTag() are NOT invoked ?

Thanks in advance!!!
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tiffiny Yang:
public int doAfterBody() {return EVAL_BODY_INCLUDE; }


doAfterBody() has to return either EVAL_BODY_AGAIN or SKIP_BODY. In your case, I guess it should be SKIP_BODY (which means you can go with the default implementation and not define that method in both your tag handlers).
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried both EVAL_BODY_AGAIN and SKIP_BODY. None of them will invoke doEngTag() function.

EVAL_BODY_AGAIN will loop forever and SKIP_BODY has no effect either.

Any suggestions

Thanks
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public int doEngTag() throws JspException, IOException
{
out.print(" Done.");
System.out.println("doEngTag() in GetParentTag ");
return SKIP_PAGE;
}
}[/QB]


What happens if you return EVAL_PAGE in your inner tag's doEndTag method?
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind guys.
It works now.

It costed me more than half day... this moringing all of sudden it works.
Thanks
 
Francisco Neto
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is in the exception thrown by the three methods: doStartTag, doAfterBody, and doEndTag.

The signature of these methods are:

1 - public int doStartTag() throws JspException

2 - public int doAfterBody() throws JspException

3 - public int doEndTag() throws JspException

I hope it helps,
Francisco.
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting progess now, but till strange.

now I can see that doAfterTag()and doEngTag() get invoked from OutTag class, BUT these two mehtod won't get invoked inside GetParentTag class.

Here's adjusted the code by adding throws JspException
--- OuterTag.java
package coreservlets.tags;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import java.io.*;
public class OuterTag extends TagSupport
{
private int count;
JspWriter out ;
public int doStartTag()
{
System.out.println("--OuterTag class , doStartTag()-- ");
out = pageContext.getOut();
try{ out.print("Count==>"+count); }
catch(Exception e){ }
return EVAL_BODY_INCLUDE;
}

public void setCount(int count) {this.count = count; }
public int getCount() { return this.count; }
public int doAfterBody() throws JspException
{
System.out.println("doAfterBody() in OuterTag class.");
return SKIP_BODY;
}
public int doEndTag() throws JspException
{
System.out.println("doEndTag() in OuterTag class.");
try{ out.print("<br>Bye!"); }
catch(IOException e){ }
return SKIP_PAGE;
}
}

--GetParentTag.java
package coreservlets.tags;
import java.io.IOException;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
public class GetParentTag extends TagSupport
{
JspWriter out;
public int doStartTag() throws JspException
{
System.out.println("**GetParentTag class , doStartTag() **** ");

OuterTag parent = (OuterTag)this.getParent();
JspWriter out = pageContext.getOut();
try{ out.print("Count value of parent ="+parent.getCount()); }
catch(Exception e){ }
return EVAL_BODY_INCLUDE;
}
//why don't run?
public int doAfterBody() throws JspException
{
System.out.println("doAfterBody() in GetParentTag class.");
return SKIP_BODY;
}
////why don't run?
public int doEngTag() throws JspException, IOException
{
System.out.println("doEngTag() in GetParentTag ");
out.print(" Done!!");
return EVAL_PAGE;
}
}
-----

why? anybody can help?

Thanks
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. I made it work.

There are some typos in GetParentTag.java:

1) you declared doEngTag() method instead of doEndTag()
2) also doEndTag() should not throw IOException, only JspException
3) in doStartTag() you are doing

which is obscuring the out member of your GetParentTag class. So when you will try to use out in the other two methods out will still be null. I think you'll get a NullPointerException in that case (the fact that you are not seeing it right now is because neither doAfterBody() - because there is no body in your JSP for this tag - and doEngTag() - well, you know why now - are not being called).

I think that's all.
[ April 24, 2007: Message edited by: Sergio Tridente ]
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sergio again.

You're absoluately right.

The typo is definitely wrong.
The second is in my jsp file, it's empty tag, so even in doStartTag() return EVAL_BODY_INCLUDE, it wont even invoke the doAfterTag or doEndTag().
The last is that I should use pageContext.getOut() in the right place.

I am so happy all my mistakes, questions, and confusion are get cleared out.

Thanks everybody who helps me.
Tiffiny
 
Tiffiny Yang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The second is in my jsp file, it's empty tag, so even in doStartTag() return EVAL_BODY_INCLUDE, it wont even invoke the doAfterTag or doEndTag().


should be
The second is in my jsp file, it's empty tag, so even in doStartTag() return EVAL_BODY_INCLUDE, it won't even invoke the doAfterTag , but only doEndTag().
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic