Forums Register Login

Including JSP templates in Taglibs

+Pie Number of slices to send: Send
I would like to write a taglib that essentualy wraps the tag body with a template. Something like this:



I can do this. But the template is not small. It will result in a bunch of out.println() statememts (or building a bunch of string buffer appends - you get the idea). That is not quite optimal. Tag Files would seem to be the obvious answer here but our app server does not support that yet...

So is there an easy way to keep the templates in JSP or HTML files and then use them in the taglib by including them? Is this a stupid thing to do?

Thanks in advance...
+Pie Number of slices to send: Send
Sorry, but I am not understanding what your issue is.
+Pie Number of slices to send: Send
Sorry. Let me be more clear. I would like the taglib to look something like this when I use it:



The output from this taglib would look like this:



If I were using a tag file instead of a taglib it would look like this:


This would be really cool. But I do not have the option to do this. The app server I am using does not support tag files. So I have to fall back on taglibs. These I do not know as well.

If I understand correctly, this is the way I would have to write the taglib:


Wow. Now we are back to the problem with Servlets and outputting text. Tons of println statements all over the place. When this template gets more dynamic, things really get complex. Simply put, this would really bite if the template gets bigger than this.

What I would like to do is break out the html template text into separate files. Then I would include them. I could do this with static html files getting it as a resource. But what about JSP files that need to be dynamic? As in, part of the header is the title. If I had a header.jsp include file, I would need to pass the title to it so that part of the template can populate it in the header.

The best option appears to be to find a templating library and use it. I have used Tiles before. I liked it. We have not been using it here. Maybe this is time to convince the powers that be to start using Tiles or some other templating system. I think performance has kept us away from them. In the mean time, I need to see if there is a way we can do this without Tiles.

Another aproach would be to toss out the taglib idea and use <jsp:include> with <jsp aram>. That, too, would work, but there is a disconnect between the header and footer.



So I am stuck. I need templates. I don't want to create a taglib that has a ton of prinln statements. Tag files are not an option. I would like to use my own taglib if I can. But I don't know how to include dynamic JSP files in my taglib.

Any suggestions?
+Pie Number of slices to send: Send
A few things.

Firstly, I would not try to do everything in doStartTag. Your tag naturally prefixes and suffixes its content, so emit the prefix in doStartTag and the suffix in doEndTag.

Secondly, I can understand your reluctance to build markup in Java. It's a bear (no pun) to maintain.

You might be interested in this blog entry that I wrote a while back.
+Pie Number of slices to send: Send
That is exactly what I was looking for! You are the man!!
Your buns are mine! But you can have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2576 times.
Similar Threads
using jsp to allow a customizable look and feel GUI
Struts with Resin
two questions about struts's template taglib
Usings custom tags within your tag handler class
Stream Closed Error
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:16:27.