Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Tag that contains result of another

 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a method getURL() in a POJO FOO that does:



In another method, I have code that does:


In my Custom Tag I am doing:


The problem is that the Tag is not evaluating the contents in getURL() but is representing it "<customTag><% mywriter.write(out); %></customTag>"
How can I make the custom reevaluate the contents of the other tag as well?
Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. Custom tags are evaluated and translated into code during the translation phase of the JSP life cycle. Your call to getURL() is not executed until the execution phase.

In order to cause a custom tag to be evaluated it must be part of a JSP. You might want to investigate the request dispatcher include mechanism, or tag files (if you are using JSP 2.0).
 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer. As I had mentioned, I have a Cutomer tag <tag1>. In the tag I am trying to write to the stream another tag, <tag2> with out.write("<tag2");

This does not seem to work even if the page references the tld that contains the tag. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. As I said, any custom tag that you emit as text will remain just that: text.

If you want to dynamically include a custom tag in another, you need to put the nested tag in a JSP file that can be included via the request dispatcher.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's something that I wrote that's somewhat related and may give you some ideas.
 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear. I liked what you wrote and am trying to work with it. I was if it could be posssible to include different taglets on the same page with pageInclude? For example,


If not can you suggest a way this could be accomplished?

Thanks....
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, why not? It's all just Java code.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Btw, you can make all this much simpler by using tag files under JSP 2.0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic