I recently had reason to develop a new view type for Maverick, and
wonder if there might be any interest in it.  If so, perhaps I can
contribute it back to the project.

The problem: I needed a very simple X?HTML template system.  It had to
be something that, however, complicated under the hood, could be used
by junior developers and design people.  I also wanted the source
pages to be valid XML, so that I could use the various XML tools to
edit/process/test the pages.

I wanted to avoid JSP's scriptlet syntax.  JSTL might work, but I
wanted the source pages to be valid XML, so I wanted to avoid stuff
like

 <a href="<c:out value='...'/>"> ... </a>

Basically, I wanted XML source files, with the ability to dynamically
evaluate expressions and a some minimal amount of flow control.
Looping, for sure.  Conditionals, probably.  Something to match the
minimalist spirit of Maverick itself.

Something that might look like this (with some of the namespace stuff
cleared away):

 <html>
  <body>
   <h2>Welcome ${user.fullName}</h2>
   Your order contains the following items:
   <table>
     <ctl:for-each items='${order.items}' name='item'>
       <tr><td>${item.productId}</td><td>${item.description}</td></tr>
     </ctl:for-each>
   </table>
   
   the current time is ${util.dateTime}

  </body>
 </html>

looks a bit like JSTL, but is required to be valid XML, unlike
JSP+JSTL.  I used OGNL for the expression language.

The processing model goes like this: the "page description" (e.g. the
above sample) is loaded once at app startup and parsed as a stream of
SAX events.  The events are recorded, and we do a certain amount of
pre-processing, e.g. joining and "compiling" text nodes.  Then, at
request time we replay the event stream using a request specific
"evaluation context" that contains things like the current request,
the authenticated user, and some utilities.  Maverick makes this
pretty simple, because we can grab the "next transform step" in the
view handler, and send the replayed SAX events on down the line.

This means that any XSTL we might want to perform can be specified in
Maverick's config, and will be handled completely by Maverick.

Another nice thing about this is that unlike using JSP+XSLT, where
the output of the JSP has to be re-parsed on every request, in my
system the source is parsed exactly once.

The strange thing about all this is that I wasn't able to find
anything that quite suited my purpose.  So I guess that's one purpose
of this message: to see what I may have missed in the sea of Java
webapp frameworks.

The other purpose is to see if there's any interest in this.  If not,
then I must have missed something, because I've been quite pleased
with the results.  If so, then I can see about getting it cleaned up
and put out somewhere for the Maverick community to have a look at.

-- 

joe


-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
[INVALID FOOTER]

Reply via email to