Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Issue with BodyTagSupport  RSS feed

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I am actually trying to make a taglib which is responsible to display few lines which are constants (depends on no attributes or content). Actually the last line is a simple html line ("<script>...</script>"), the rest is a call to another tag (this call is always the same call ("<mytag>...</mytag>").

How to make it work ? Here is a part of what I have done:

public class IncludeCalendar extends BodyTagSupport {

private BodyContent bodyContent;

public void setBodyContent(BodyContent bodyContent) {
this.bodyContent = bodyContent;
JspWriter out = bodyContent.getEnclosingWriter();
try {
out.println("<mytag>...</mytag>");
} catch (IOException ex) {
ex.printStackTrace();
}
}

public int doStartTag() throws JspException {
return this.EVAL_BODY_BUFFERED;
}

public int doEndTag() throws JspException {
try {
JspWriter out = pageContext.getOut();
out.print("<script language=\"Javascript\" type=\"text/javascript\"> .... </script> ");
} catch (Exception ex) {
ex.printStackTrace();
}
return EVAL_PAGE;
}
}

Apparently the body is not processed... it displays only the tag html <script>

Thanks in advance for your help,
Adri
 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
B'coz the doAfterBody() method returns skip-body by default, therefore,it has not processed the body. implement the doAfterbody and return eval-body-again/buffered.
Try it & don't forget to post the result whatever u got.
 
Adri Smith
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First I would like to thank you a lot for spending a little time to help me.

Actually I have tried to in fact return EVAL_BODY_BUFFERED it displays in my HMTL generated page:
<mytag>...</mytag>
<script>...</script>

This is better but the tag <mytag> is not translated... Do you have an idea how to make it translated ?

Thanks again for your precious help,
Adri
 
Deepa Korecherla
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Explain ur problems clearly...its hard to understnd..make it more clear
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!