• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BodyTagSupport's return value EVAL_BODY_BUFFERED

 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a class that extends BodyTagSupport, the default return type of doStartTag() is EVAL_BODY_BUFFERED. If I invoke the tag with empty body, the container returns SKIP_BODY(because of it, the container executes doEndTag()). At what stage,(the lifecyle of BodyTagSupport) the container knows, the tag has no body, that's why I have to return SKIP_BODY? Thankyou.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

If you didn't overide the doStartTag() method in your tag class, then the default value of doStartTag(i.e EVAL_BODY_BUFFERED in this case) will be invoked.

If we are sticking to the default value,then your class will execute the next method which is doInitBody() in this case,and doInitBody() will execute and compiler will execute the next method that is doAfterBody(). The default value of doAfterBody is SKIP_BODY.

so it will go the doEndTag() method and rest of the story continues.

Hope you understand.


 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, UdayKumar thanks for your reply. I think doInitBody() will be called after setBodyContent(). As far as I know, if the doStartTag() returns EVAL_BODY_BUFFERED, the container calls the pageContext's pushBody(), and the pushBody() creates BodyContent object,which is sub class of JspWriter(by encapsulating the body of the tag) and will return. Then the container sets the BodyContent via setBodyContent(BodyContent bc), after it will call doInitBody(), then the body is evaluated by the container. The whole above process will be happens when the tag invokes with the body and if the doStartTag() returns EVAL_BODY_BUFFERED.
If the tag is not invoked by body, and if we return EVAL_BODY_BUFFERED, the above process will not happen. It will directly executes doEndTag()(the doEndTag() tag will be execute only if the method returns SKIP_BODY). My question is at what stage, the container knows, that the tag has no body, that's why I (container), have to return SKIP_BODY. Thankyou.
 
udaykumar maddigatla
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

what you said is correct. I didn't gone to too deep of setInitBody() ... all those stuff.

When we are creating the tag, in our .tag file we have to specify the behaviour of the tag in perspective of body by using the tag called


So by the time when container sees the tag it will try to see the syntax (i.e is tag followed what it specifies in .tag file).

So in our case the tag can contain the body. If body is there then body will processed. otherwise container will know by seeing the syntax of the tag.

 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Uday Kumar. Thanks for your reply.
 
reply
    Bookmark Topic Watch Topic
  • New Topic