This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EVAL_BODY_TAG doesnot work within nested tags

 
wessel zaalberg
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I study the book advanced Javaserver pages by David M Geary. A very good book. I downloaded the code and I notice that an iteration that gives me the column names works but when I iterate over rows and columns the return EVAL_BODY_TAG doesnot work.
I have installed the jakarta-tomcat server v3.2.1, OS W2K and I start it on the cmmandline. There is data, I write them to the command line so I can see that the iteration works. Only nothing gets written to the body.
This really has me stumped, any ideas would be greatly appreciated.
 
Tim Holloway
Bartender
Posts: 18423
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have a clear enough picture here. Maybe you could provide some more info?
 
wessel zaalberg
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What works is this

columNames iterates over the available columns and returns each name.
What surprisingly doesnot work is a nested iteration: ie rows and columns.

In both classes I write to the commandline so I can see what is happening and everything goes as it is supposed to except nothing gets written to the body of the page.
With every column I return EVAL_BODY_TAG until I am at the end of the row then it is SKIP_PAGE the next row is selected and I come back in the column iterator.
 
Adam Chace
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you might not be sending the contents of the temporary buffer (the enclosing JspWriter) to the browser. Your doAfterBody() should look like:
public int doAFterBody() {
try {
BodyContent body = getBodyContent();
JspWriter out = body.getEnclosingWirter();
out.println( body.getString() );
if ( <your condition> ) {
return( EVAL_BODY_TAG );
} else {
return( SKIP_BODY );
}
...
------------------
Adam Chace
Author of :JSP Tag Libraries
Chalk Creek Software
 
wessel zaalberg
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I do is :
public class ColumnsTag extends ColumnIteratorTag {
public void doInitBody() throws JspException {
setAttribute();
}
public int doAfterBody() throws JspException {
int whatNext = super.doAfterBody();
//we have here a skip_body or eval_body_tag based on the availability of a column
if(whatNext == EVAL_BODY_TAG)
setAttribute();
return whatNext;
}
private void setAttribute() throws JspException {
try {
pageContext.setAttribute(getId(), rs.getString(
currentColumn));
-----------------
the set attribute should have given value the value of the column. If that doesnot happen at least I expect the <TD></TD> to have been written, the page doesnot seem to recieve the EVAL_BODY_TAG which has been returned.
 
Trevor Dunn
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may be totally offbase here as to what your problem is given the limited information but based on the assumption that you are trying to access what the current row is from the ColumnsTag.
Originally posted by wessel zaalberg:
public class ColumnsTag extends ColumnIteratorTag {
public void doInitBody() throws JspException {
setAttribute();
}
public int doAfterBody() throws JspException {
[b]int whatNext = super.doAfterBody();[b]
//we have here a skip_body or eval_body_tag based on the availability of a column
if(whatNext == EVAL_BODY_TAG)
setAttribute();

It seems to me that you are assuming because ColumnsTag extends ColumnIteratorTag that if it is nested inside a ColumnIteratorTag that you can automatically call methods on it and get the current value of the outside iterator. You can not do this. The two tags are separate and are two different objects. Your call to super is not calling the outside nested tag. It is the same as if you have two classes 1.Animal 2.Dog
and you do the following
Animal a = new Animal();
Animal b = new Dog();
"b" can not access any data in "a" by calling super just becuase it extends "a". I know with nested tags this might get a bit confusing but there is a solution. Store the current iteration of the ColumnsTag in a variable so you can access it, then in your ColumnsTag tag use the following code

This will give you a reference to the enclosing tag that you can then use

Trevor
 
wessel zaalberg
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I am going to give it a try.
[edit]
which I did.
Alas I now get a pagehandle exception :
javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
And in root cause :
java.lang.NullPointerException
at tags.jdbc.ColumnsTag.doAfterBody(ColumnsTag.java:15)

Besides with super or parent in both cases I get EVAL_BODY_TAG returned, but apparently wiht parent I have lost pagecontext.
Or maybe I lost it more explicitly then before.
[/edit]
[This message has been edited by wessel zaalberg (edited July 30, 2001).]
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!