Forums Register Login

EVAL_BODY_TAG doesnot work within nested tags

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
I don't have a clear enough picture here. Maybe you could provide some more info?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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).]
His brain is the size of a cherry pit! About the size of this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 798 times.
Similar Threads
polymorphism
sum of rows
Collection Doubt
doAfterBody not being run when using IterationTag
eclipse - active editor does not contain a main type
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:33:25.