Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom tag question:

 
Jingh Yi
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My tag handler class:


My view.jsp:

My TLD:


My question:
How come in doAfterBody(), second line, getBodyContent() returns null?

Thanks!
Jenny
 
Osama Hasan
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jenny!
You should return EVAL_BODY_BUFFERED instead of EVAL_BODY_INCLUDE.
Hope it helps.
 
Jingh Yi
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Osama! It's so cool. It worked after I did what you said.

But... I'm confused... when doStartTag() returns EVAL_BODY_INCLUDE, doesn't the control go to evaluate body? why do I have to have EVAL_BODY_BUFFERED? I don't have setBodyContent() or doInitBody() defined.

Thanks!
Jenny
 
Osama Hasan
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jenny!
BodyContent is available only when the body is buffered. Thus, when we return EVAL_BODY_INCLUDE from doStartTag() the body is not buffered and hence BodyContent is not available.
 
Jingh Yi
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh thanks, Osama! I didn't know that.

BTW, can I implement the body iteration by using TagSupport?
 
Osama Hasan
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The TagSupport class implements the IterationTag interface. So, you certainly can.
 
Jingh Yi
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Osama,

I tried to extend TagSupport, but couldn't compile. getBodyContent() is not recognized. How do I get body content then?

Thanks!
Jenny
 
kapil munjal
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to find out...if getBodyContent() method belongs to BodyTagSupport class.

That can be the only reason.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic