[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [JS] Velocity Templates vs. JSP
This e-mail is a little off-topic for this thread.
I don't know anything about Velocity Templates, but I
wanted to share the architecture we used with our
latest project involving JSPs and servlets since this
topic seems to resurface often.
We have a dumb servlet that deligates all of the
application control logic to a controller by creating
a TreeMap from an HttpServletRequest then passes the
TreeMap to the controller. The servlet puts the
controller in the session and each JSP page pulls out
the controller and creates a renderer from it:
<%
ServicesBillingController sbc =
(ServicesBillingController)
request.getSession().getValue("SAPCssController");
ProcessLaborRenderer plr = new ProcessLaborRenderer(
sbc );
%>
Now the JSP page has a renderer and we just call
methods on the renderer to get the info we want. We
leave the HTML on the JSP page as much as possible and
simply have the renderer dig into the controller and
extract the information we need. In this project
we're doing billing so we often times have the
renderer formatting a double as a currency. Here's an
example:
On the JSP page:
<%=plr.getTotalAmount()%>
and the renderer method looks like this:
public String getTotalAmount() {
return formatCurrencyString(
getController().getServicesBilling().getCurrentSection().getResourceGroupLabor().totalAmount()
);
}
We have about 30 JSP pages and typically one custom
renderer per JSP page but we did use a few renderers
more than once.
We don't unit test the renderers, they either work or
they don't, but we are able to unit test the
controller since it's separated from the servlet.
This architecture gives us a distinct separation
between our model and view and minimizes the
complexity of the JSP pages.
I looked at taglibs recently and couldn't find any
advantage over the architecture we're using. In fact,
it looked to me like it would add a layer of
complexity over what we currently have.
One disclaimer here is that we had programmers
creating the JSP pages and integrating HTML done by a
graphic artist. Still, we could turn the pages over
to someone who doesn't know anything about Java and
all they would have to do is say "Hey, can I get a
getFoo() method added to the ProcessLaborRenderer that
gives me 'blah, blah, blah'?". We add the method and
they're off and running.
--- Cynthia Jeness <cj@goldencode.com> wrote:
> Dion,
>
> I recognize that Jon is not unbiased in his opinion;
> however, a couple of points that he has made do seem
> to make sense -- at least in my very
> limited experience. First, I find JSP somewhat
> reminiscent of JDBC in that it seems to be a quick
> fix to attract programmers already familiar
> with a competing technology. Over my years of
> working with JDBC, I have come to dislike it a lot
> and try to hide it as much as possible in my
> systems. Actually, I think that I have come to
> dislike relational databases, but that is another
> whole discussion.
>
> Second, I went to two talks recently give by Hans
> Bergsten on JSP. His solution to MVC was to avoid
> scriptlets and use Taglibs. However, I
> have also gone to presentations on Taglibs and they
> seem very fragile in terms of the setup required.
> Perhaps the Java Standard Taglibs will
> solve this.
>
> From my perspective, it is important to separate the
> HTML from the Java logic because I would like to
> delegate the HTML production to good web
> designers who may in fact be "marketing people" with
> little technical skill. I am a littler concerned
> that this is a practical goal with
> JSP.
>
> So, in short, I am not so concerned about the fact
> that I can do bad things. I am more concerned about
> how easy it is to do good things.
>
> Cindy
>
>
> dion@multitask.com.au wrote:
>
> > Jon's a well known opponent of JSPs, so I take
> what he says with that in
> > mind.
> >
> > I reviewed one of Jon's documents (the infamous
> ymtd doc on the velocity
> > site), and found it to be full of holes.
> >
> > Nothing is ever perfect. The JSP spec lets you do
> bad things. So does Java
> > the language. I'm over it.
> >
> > But I prefer to spend my time doing work with
> technology than playing 'mine
> > is better' games.
> > --
> > dIon Gillard, Multitask Consulting
> > Work: http://www.multitask.com.au
> > NetRexx: http://www.multitask.com.au/NetRexx.nsf
> >
> >
> > Cynthia
> > Jeness To:
> ajug-members@ajug.org, javasummit@yahoogroups.com
> > Sent by: cj cc:
> > Subject:
> [JS] Velocity Templates vs. JSP
> >
> > 01/08/2001
> > 02:42 AM
> > Please
> > respond to
> > javasummit
> >
> >
> >
> > In the July, 2001 Java Developer's Journal, Jon
> Stevens wrote an article
> > comparing Velocity Templates versus JSP as tools
> for developing
> > web-based applications. This month's Java World
> also featured an
> > article on Velocity. Since Jon is one of the
> founders of the Velocity
> > project, his article favored the use of templates
> rather than JSP.
> > Since I may be engaged in more web-based
> development shortly, I am
> > curious how others feel about the pros and cons of
> these two
> > technologies.
> >
> > Cindy
> >
> > http://www.bobrow.net/kimberly/JavaSummit for info
> on
> > subscribing/unsubscribing
> >
> > Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
> >
> > ------------------------ Yahoo! Groups Sponsor
> ---------------------~-->
> > Secure your servers with 128-bit SSL encryption!
> Grab your copy of VeriSign's FREE Guide: "Securing
> Your Web Site for Business." Get it Now!
> >
>
http://www.verisign.com/cgi-bin/go.cgi?a=n094442340008000
> >
>
http://us.click.yahoo.com/n7RbFC/zhwCAA/yigFAA/saFolB/TM
> >
>
---------------------------------------------------------------------~->
> >
> > http://www.bobrow.net/kimberly/JavaSummit for info
> on subscribing/unsubscribing
> >
> > Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
=====
Matthew Avery
Engineering Innovation, Inc.
E-Mail: avery1701@yahoo.com
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/