Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom JSP tags

 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question about implementing a class for a custom tag that extends BodyTagSupport. If the doStartTag() method returns EVAL_BODY_BUFFERED I know a BodyContent object is automatically created and the doInitBody() and doAfterBody() methods are called. The doAfterBody() method I'm looking at will get a JspWriter and write out the BodyContent. My question is I don't see where data is added to the BodyContent object. There is some code in the doInitBody() and doAfterBody() that can call pageContext.setAttribute() with data to be displayed by the JSP page. Does these calls to pageContext.setAttribute() cause the data to be saved in the BodyContent object?

Thanks
 
Stefan Evans
Bartender
Posts: 1712
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reference: http://docs.oracle.com/javaee/6/api/javax/servlet/jsp/tagext/BodyTag.html

The setting of the body is done by the servlet container you are running in.
It is doing stuff in the background and just every now and again consulting you to find out what you want to do with it.

According to the lifeCycle it will setBodyContent() before calling doInitBody()
It will then call evaluate the body, and call doAFterBody()

The logic around setting the body and evaluating it is internal to the servlet container
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic