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

SimpleTag how to get body in Tag class?

 
Marc van Dam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a question. At this moment I'm studying for SCWCD.

For learning purposes I setup a webapp with a SimpleTag.


With testing I found that "setJspBody(JspFragment jspBody)"
is nicely called when I use a body in my JSP page:

I tried to get "THIS BODY IS NEW!!" available in my "SimpleTagTest.java" can that be done???







The WEB.XML :



and I made an "mijntag.tld" in WEB-INF/tags:




and I made the SimpleTag Java Class:






kind regards,
Marc van Dam
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you see, the setJspBody method receives a JspFragment object. JspFragment has an invoke method which takes a java.io.Writer. To get the body content as a String, you can call the JspFragment.invoke method with java.io.StringWriter object and retrieve the String using toString method...
 
Ankit Garg
Sheriff
Posts: 9580
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to javaranch Marc...
 
Marc van Dam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

Yes, it works!! Nice that even that is possible.

Thanks for the help.

kind regards,
Marc van Dam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic