• 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

Custom tag generating JSP code?....

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, Bill, thanks, will do...

P.S. There's such a bloody mess in it...
 
reply
    Bookmark Topic Watch Topic
  • New Topic