tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Clark <>
Subject Re: Bending Jasper to My Will
Date Tue, 22 Apr 2008 02:16:23 GMT
Thanks for everyone with their quick responses to
my query regarding how to override tags/JSP files.
My initial posts on the subject can be found here:

Many people suggested that I try various frameworks
for the application because they contain template
engines that may work for my purpose. Unfortunately,
I think that this is a non-starter because the app
is already written (quite nicely, I might add) in
straight JSPs.

I took a quick look through the various projects'
websites and documentation. It seems like they all
do roughly the same thing and that many of them
are like JSPs but with their own custom syntax.

That aside, I didn't see anything about how to skin
the app at the level that I want. I saw mechanisms
to use different templates for entire responses but
nothing about overriding individual parts of those
templates. Granted, I could be completely wrong
about any and all of these points because I don't
have first-hand experience with these frameworks.

Anyway, I'd like to clarify my needs a little
further because it didn't seem that the example in
my second post was clear. First, my requirement
are that it use straight JSPs. Second, I must be
able to override any tag or JSP included from another
tag/JSP file, not just whole response pages. Let me
use a more complex example.

Say I have the following response page and source
files: [created just for discussion and edited for

   <%-- file: response.jsp --%>
     <my:header cols='${cols}' />
     <my:body rows='${rows}' />

   <%-- file: /WEB-INF/tags/table.tag --%>
     <jsp:doBody />

   <%-- file: /WEB-INF/tags/header.tag --%>
   <%@ attribute name='cols' type='java.util.List' %>
     <c:forEach var='item' items='${cols}'>
       <my:headerCell data='${item}' />

   <%-- file: /WEB-INF/tags/headerCell.tag --%>
   <%@ attribute name='data' type='java.lang.Object' %>

   <%-- file: /WEB-INF/tags/body.tag --%>
   <%@ attribute name='rows' type='java.util.List' %>
   <c:forEach var='row' items='${rows}'>
       <c:forEach var='cell' items='${row.cells}'>
         <my:rowCell data='${cell}' />

   <%-- file: /WEB-INF/tags/rowCell.tag --%>
   <%@ attribute name='data' type='java.lang.Object' %>

Looking at the result, the contents of the page are
the result of the composition of all of these JSPs
and tags, structured like so:


What I need is the ability to override any one of
these parts independently and based on a user pref.
Given User 1, 2, and 3 who have skin preference of
<undefined>, "Foo", and "Bar", respectively, the
output they each see for response.jsp can be

The base case, User 1, that does not have a skin
specified would see the response as structured like
I illustrated above. However, skin "Foo" may replace
the response.jsp file but leave the rest in place.
And skin "Bar" may just replace headerCell.tag and
rowCell.tag. For skin "Foo", the response page
should be different but should continue to use all
of the default tags. Whereas for skin "Bar", the
response page table, header, and body tags stay the
same; but the custom header cell and row cell tags
are used instead of their defaults.

In the last case, the structure of the response
should look like this:


Notice that the JSP/tag files that compose the
response are a mixture of the default ones and the
custom ones that the skin overrides. Skin authors
should not have to make complete copies of the
default skin tree in order to edit only a handful
of files; the system should make that transparent
to them.

Does this make it any clearer? My apologies if the
frameworks mention do exactly this and I just didn't
notice from their documentation. But since the app
is already written, it would make a massive change
to introduce an additional dependency.

As I mentioned in my first post, I browsed through
the Jasper source but didn't see any way to hook
into the JSP/tag file resolution mechanism. I
figured that I could extend a factory class or
register some kind of resolver that would allow me
to achieve the results I need. Unfortunately many
things were final and didn't provide hooks for

I'm going to be looking for reasonable workarounds
if there's no way to extend Jasper. But if anyone
know of anything else given my requirements, it
would be greatly appreciated.



To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message