aspose file tools*
The moose likes JSP and the fly likes Custom tag generating JSP code?.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom tag generating JSP code?...." Watch "Custom tag generating JSP code?...." New topic
Author

Custom tag generating JSP code?....

Dmitry Danilov
Ranch Hand

Joined: Jan 27, 2004
Posts: 38
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?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
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

Joined: Jan 27, 2004
Posts: 38
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

Joined: Mar 22, 2000
Posts: 12823
    
    5
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

Joined: Jan 27, 2004
Posts: 38
OK, Bill, thanks, will do...

P.S. There's such a bloody mess in it...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom tag generating JSP code?....