samblake
asked on
Tag library bodyContent is null
Hi,
I'm trying to greate a taglib that loops through the the body twice. There may be html in the body and I don't want that to be printed on the first iteration, only the second. I have the loop working fine I'm just stuck on the part about not printing the elnlosed html twice. How can this be achieved? I thought that I could maybe do something like:
public int doAfterBody() throws JspException {
try {
BodyContent body = getBodyContent();
body.clearBody();
.....
But getBodyContent() always seems to return null. Any ideas?
Thanks.
-Sam
I'm trying to greate a taglib that loops through the the body twice. There may be html in the body and I don't want that to be printed on the first iteration, only the second. I have the loop working fine I'm just stuck on the part about not printing the elnlosed html twice. How can this be achieved? I thought that I could maybe do something like:
public int doAfterBody() throws JspException {
try {
BodyContent body = getBodyContent();
body.clearBody();
.....
But getBodyContent() always seems to return null. Any ideas?
Thanks.
-Sam
also, can you show the tld file to make sure that the <bodycontent> element is specified as "tagdependent"
ASKER
Nah, I got it. The problem was that in the doStartTag method I was returning BODY_TAG_INCLUDE. It seems I needed to return BODY_TAG_AGAIN.
sweet! Those return values can be a real pain :-)
agreed :-)
ASKER
Yeah, the can be a pain. Especially as almost everything I find says to use EVAL_BODY_TAG which is depreciated. *rolls eyes*
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
public int doAfterBody() throws JspException {
try {
BodyContent body = getBodyContent();
String bodyContentString= body.getString() ;//gets content
body.clearBody();
and you need to make sure that the previous iteration over the tag has not cleared the content by calling body.clearBody()