Link to home
Start Free TrialLog in
Avatar of samblake
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
Avatar of bloodredsun
bloodredsun
Flag of Australia image

Surely it should be

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()
also, can you show the tld file to make sure that the <bodycontent> element is specified as "tagdependent"
Avatar of samblake
samblake

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 :-)
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
Avatar of PAQ_Man
PAQ_Man
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial