[Logo]
Forums Register Login
Custom tag generating JSP code?....
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?
 
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
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...
 
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
OK, Bill, thanks, will do...

P.S. There's such a bloody mess in it...
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 17, 2017 10:57:44.