tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Clark <a...@cyberneko.net>
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:

http://mail-archives.apache.org/mod_mbox/tomcat-users/200804.mbox/%3c48092B8C.2090309@cyberneko.net%3e
http://mail-archives.apache.org/mod_mbox/tomcat-users/200804.mbox/%3c480CE05E.6030208@cyberneko.net%3e

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
brevity]

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

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

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

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

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

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

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:

   response.jsp
     /WEB-INF/tags/table.tag
       /WEB-INF/tags/header.tag
         /WEB-INF/tags/headerCell.tag
         ...
       /WEB-INF/tags/body.tag
         /WEB-INF/tags/rowCell.tag
         ...

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
different.

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:

   response.jsp
     /WEB-INF/tags/table.tag
       /WEB-INF/tags/header.tag
         /skins/Foo/tags/headerCell.tag
         ...
       /WEB-INF/tags/body.tag
         /skins/Foo/tags/rowCell.tag
         ...

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
extension.

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.

Thanks!

-AndyC

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message