This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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...
The squeaky wheel gets the grease. Well, that or replaced...
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.