You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Timothy Colson <tc...@cisco.com> on 2001/04/19 17:38:01 UTC

Struts Servlet Controller + Velocity Template Views

Howdy Folks -

First off - I applaud Gier for all of his effort on Velocity which is
exceptionally good at what it does - process templates. Second - I
appreciate his candor and support on this list, nothing short of fantastic.

Okay - enough sucking up - on towards the point! :-)

> Manny Holguin wrote:
> > Having moved from JSP and Struts to Velocity, I would just as soon never
> > hear about those technologies again :)
>
Gier, the Humorous, replied:
> Ok.  From now on, we will refer to them as 'Rupert'.

Gier, the Benevolent, added:
> Honestly, I have only nice things to say about Struts.  It seems well
> thought out, and the toolkit that it provides seems very nice.

And Gier, the Sarcastic, wrote:
> JSP is another story :)


The point I have to make is that many of the folks/colleagues I've spoken to
about Velocity/Struts seem to have a difficult time NOT comparing them
directly. They don't seem to understand, at least initially, this is
comparing apples to oranges.

Consider the following matrix:

Controller Framework + View Component
-------------------------------------
'RollYourOwn'       + JSP
'RollYourOwn'       + Velocity
Struts              + JSP
Turbine             + Velocity

>From this, we see that the comparison should ALWAYS be between Velocity and
JSP. Actually, to be completely correct, we need to compare Velocity with
JSP only in the role of a VIEW component.

On that - I personaly feel it's an easy argument. HINT: JSP loses most every
time. ;-)

Please note - if you want to compaure using Velocity and JSP to throw a SQL
query at a database, you're again barking up the wrong tree as Velocity
isn't built to do that. JSP, since it's Java, can do it... but, that starts
a theological argument over whether a VIEW component should be allowed to do
that. Velocity settles the argument right quickly - by not allowing it.


Back to Struts...

Up until Gier's work on Struts+Velocity, the Strut framework has been
married to JSP as it's only View Component option.  However - as proven by
Gier, Velocity can be used instead of JSP.

Back to our matrix:

Controller Framework + View Component
-------------------------------------
Struts            + JSP        = Ugh. Struts good but JSP Baaaad!
Struts            + VELOCITY   = Yippee! Struts and Velocity both Good!

It works! It's elegant. It's a win-win, IMHO of course. :-)

The Struts team has indeed written a handy servlet controller framework - I
encourage everyone to have a serious look at their fine work!

I encourage Gier to continue to "borrow and steal" any/all of the good bits
from Struts....it's no surprise to me that the only part conspicuously
missing from the Velocity Struts Package is the .jsp filetype <grin>

Cheers,
Timothy Colson
IT Engineer
tcolson@cisco.com


Re: Struts Servlet Controller + Velocity Template Views

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Timothy Colson wrote:

>
[SNIP

Thanks for the kind words.

> 
> The point I have to make is that many of the folks/colleagues I've spoken to
> about Velocity/Struts seem to have a difficult time NOT comparing them
> directly. They don't seem to understand, at least initially, this is
> comparing apples to oranges.

That's my biggest problem with the whole Turbine/Struts/JSP/Velocity
soup - people can't seem to shake the View from the other parts.

I think that Velocity (and WebMacro, of course) is a very subtle but
significant model shift from JSP.  It's not simply replacing tags with
Velocimacros/directives.  There something more.  For example, the
multi-tiered 'scope' business in JSP appears to be a bare, naked view of
the underlying servlet infrastructure with no attempt to normalize into
a single-tier 'view' that the Velocity/WebMacro context provides.

So for me, the motivation is to make Velocity accessable to those that
'think in JSP'.

> Consider the following matrix:
> 
> Controller Framework + View Component
> -------------------------------------
> 'RollYourOwn'       + JSP
> 'RollYourOwn'       + Velocity
> Struts              + JSP
> Turbine             + Velocity
> 
> >From this, we see that the comparison should ALWAYS be between Velocity and
> JSP. Actually, to be completely correct, we need to compare Velocity with
> JSP only in the role of a VIEW component.

Well, there have been a few examples of using templates for control as
well.  I've done it a little myself - the model being a quasi-pull where
the context was stocked with what I needed, and it was easy to do my own
application control.  Granted, it wasn't a complicated application by
any stretch of the imagination, but it was nice.  That is a common
criticism of Velocity compared to JSP -> in JSP you can simply start
prototyping w/o building a new servlet.  As we have discussed here
before, it's possible and can be even very convenient to build a small
framework that lets you do that.
 
> On that - I personaly feel it's an easy argument. HINT: JSP loses most every
> time. ;-)
> 
> Please note - if you want to compaure using Velocity and JSP to throw a SQL
> query at a database, you're again barking up the wrong tree as Velocity
> isn't built to do that. JSP, since it's Java, can do it... but, that starts
> a theological argument over whether a VIEW component should be allowed to do
> that. Velocity settles the argument right quickly - by not allowing it.

But you can do that in Velocity to some degree : an object that takes a
SQL string as an arg and returns an array of hashes....  it's just that
you have the ability to control how wacky that SQL gets... "DROP..."
 
> Back to Struts...
> 
> Up until Gier's work on Struts+Velocity, the Strut framework has been
> married to JSP as it's only View Component option.  However - as proven by
> Gier, Velocity can be used instead of JSP.

And along with JSP.  The stuts+vel stuff isn't anywhere near complete,
however.

> Back to our matrix:
> 
> Controller Framework + View Component
> -------------------------------------
> Struts            + JSP        = Ugh. Struts good but JSP Baaaad!
> Struts            + VELOCITY   = Yippee! Struts and Velocity both Good!
> 
> It works! It's elegant. It's a win-win, IMHO of course. :-)
> 
> The Struts team has indeed written a handy servlet controller framework - I
> encourage everyone to have a serious look at their fine work!
> 

And make sure you look at Turbine, of course. :) 

geir

-- 
Geir Magnusson Jr.                          geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: Struts Servlet Controller + Velocity Template Views

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Chris Shenton wrote:
> 
> On Thu, 19 Apr 2001 08:38:01 -0700, "Timothy Colson" <tc...@cisco.com> said:
> 
> Timothy> Up until Gier's work on Struts+Velocity, the Strut framework
> Timothy> has been married to JSP as it's only View Component option.
> Timothy> However - as proven by Gier, Velocity can be used instead of
> Timothy> JSP.
> 
> Excuse my newbiosity: I'm a coder but not a hard-core Java dude yet.
> Recently came across webmacro and velocity, which I expect will cure
> me from my PHP-like tendency to combine logic and view.  The Struts
> package looks very similar to something one of our coders developed
> inhouse for the Controller in MVC.  So I'd ideally like to move our
> current Java-with-HTML cruft into a proper MVC model using Struts +
> Velocity.

A word of warning - the current Struts+velocity support has just a few
hours invested in it, and really should be considered a work in
progress, an experiement.  It does show that it's easy to do, and yes, I
think there are some very nice things in Struts, but I wouldn't bet the
farm on the Stuts+Vel package.

Turbine + <template engine> has thousands of hours, and years of use. If
you really have a chance to make a fresh start with a port, make sure
that you give Turbine a good look.  It's a very active project with
strong developer support.

> 
> Almost everything I've read seems to indicate folks are using Tomcat.
> We're using Apache+Jserv and frequently talking to a a bunch of beans
> in WebLogic.  Is it possible to use Struts+Velocity in such an
> environment?

Eh. Probably, but not sure.  I am pretty sure that you will trip if you
try to use the VelocityServlet base classs for your servlets, as it
probably needs stuff from servletspec 2.2  I am moving a client off of
JServ at the moment. You might as well get it over with.  The migration
should be pretty straightforward (it is for me - others might have more
experience in this...)

And it means then that your app is structured to work with a 'modern'
servlet runner.  Tomcat is great. I really like it.  But I rest
comfortably knowing that in theory anyway, I should be able to easily
move to another servlet runner.
 
> If I sound confused it's because I am :-(.  I'd really like to start
> on the right foot with a proper MVC model and solid tools, instead of
> relying on a home-grown Controller and other hacks.

This stuff is all here in Jakarta.  Be warned - the documentation
sometimes takes a back seat to performance and features, so don't judge
things by documentation.

geir

-- 
Geir Magnusson Jr.                               geirm@optonline.net
Developing for the web?  See http://jakarta.apache.org/velocity/

Re: Struts Servlet Controller + Velocity Template Views

Posted by Chris Shenton <cs...@Outbounder.com>.
On Thu, 19 Apr 2001 08:38:01 -0700, "Timothy Colson" <tc...@cisco.com> said:

Timothy> Up until Gier's work on Struts+Velocity, the Strut framework
Timothy> has been married to JSP as it's only View Component option.
Timothy> However - as proven by Gier, Velocity can be used instead of
Timothy> JSP.

Excuse my newbiosity: I'm a coder but not a hard-core Java dude yet.
Recently came across webmacro and velocity, which I expect will cure
me from my PHP-like tendency to combine logic and view.  The Struts
package looks very similar to something one of our coders developed
inhouse for the Controller in MVC.  So I'd ideally like to move our
current Java-with-HTML cruft into a proper MVC model using Struts +
Velocity.

Almost everything I've read seems to indicate folks are using Tomcat.
We're using Apache+Jserv and frequently talking to a a bunch of beans
in WebLogic.  Is it possible to use Struts+Velocity in such an
environment?

If I sound confused it's because I am :-(.  I'd really like to start
on the right foot with a proper MVC model and solid tools, instead of
relying on a home-grown Controller and other hacks.

Thanks.