This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Custom tag generating JSP code?....  RSS feed

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

Is it at all possible for a custom tag to generate JSP code and have it evaluated by the JSP page?

I tried to do the following as a test:
I wrote a class that extends TagSupport and outputs a very simple jsp expression like as a String. Then I wrote another class that extends BodyTagSupport, set its <body-content> to accept JSP, and made it simply print the results of its body evaluation.
The code that does the work is as follows:

BodyContent bodyContent = getBodyContent();
JspWriter out = bodyContent.getEnclosingWriter();
String bodyString = bodyContent.getString();
if(bodyString!=null) out.print(bodyString);


Then I placed the first tag between the starting and ending tags of the second one and ran my page. The result was a bit frustrating, it was just "<%=new java.util.Date() %>", that is, the JSP expression did not get evaluated but it was just printed as is...

Anything that I did wrong?
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is it at all possible for a custom tag to generate JSP code and have it evaluated by the JSP page?


No
Think about when JSPs are compiled into servlets, what tags turn into in the compiled servlet, and when tag code runs.
Bill
 
Dmitry Danilov
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it always seemed to me that custom tags are evaluated first, then the results of the evaluation are included in the page code and then it is again evaluated as a whole, but in my case the output of a custom tag are NOT evaluated even though they represent the body of another tag which MUST accept JSP code and MUST be evaluated....

I'm still a little confused...
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, it always seemed to me that custom tags are evaluated first, then the results of the evaluation are included in the page code and then it is again evaluated as a whole


Well, thats the source of your problem. Why don't you examine the Java code created by the JSP compiler to see what tags really turn into.
Bill
 
Dmitry Danilov
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, Bill, thanks, will do...

P.S. There's such a bloody mess in it...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!