on 2/5/01 4:26 PM, "David Sean Taylor" <[EMAIL PROTECTED]>
wrote:
> No, actually it concerns me a little bit. :)
How is that? You are asking me to compare Velocity and JSP, but you aren't
really saying why other than it concerns you.
> Jon, could you briefly tell us why Velocity over JSP, and could you please
> answer a few questions?
Sure!
> JSP has the "<%@include" directive and "jsp:include" action.
> The directive includes at 'translation' time, and the action at request
> time.
> How do you go about this in Velocity?
If you use Turbine, the abstraction is already there and you don't need to
use "include".
If you use Velocity, you can create an object and place it into the Context
which "simulates" the same behavior of JSP's include tag. This would be
similar to what Turbine does by placing a $navigation object into the
Context.
If you are trying to include other Velocity templates directly, all you need
to do is this:
#parse("/path/to/foo.vm")
If you want to include a random file without processing it through the
parser:
#include ("/path/to/my.txt")
For security, the path is relative to the resource root which is a property
in a property file or configured programmatically.
> Does Velocity have custom tags?
> Nested tags?
Velocity doesn't have tags. It doesn't need them. What it does have is the
ability to place *any* object into the Context. So, for example, you could
place Turbine's RunData object into the context. Then all of its methods are
available to you in a bean like fashion...for instance:
context.put ("data", new RunData());
$data.Request
That would give you the HttpServletRequest object.
$data.Request.Method
That is the same as saying:
HttpServletRequest.getMethod()
You could also do this:
$data.getRequest().getMethod()
> Instead of using beans, how would you go about accessing bean-like business
> objects?
Through reference to the objects in the Context.
> In JSP, the scope of a bean can be controlled as "page | app | session |
> request".
> Is there an equivalent construct in Velocity?
100% Yes.
Velocity combined with Turbine gives you that scope. This is accomplished
through the use of the Pull Service (which gives you page/app level), Page
level objects (which gives you app/session) and you can always have Screen's
as well as pull based objects which give you request level scope.
@see Pull Model:
<http://java.apache.org/turbine/pullmodel.html>
Let me also mention that Velocity is a general purpose template evaluation
tool. Therefore, you can use Velocity to create static websites
<http://jakarta.apache.org/site/jakarta-site2.html>, output .sql files (@see
Turbine's Torque system), send email [2] and do many other cool things that
you just can't do easily with JSP.
[2]
<http://working-dogs.com/turbine/cvsweb/index.cgi/turbine/src/java/org/apach
e/turbine/util/velocity/>
Velocity kick's JSP ass so badly, in so many ways, it is silly. I'm going to
start working on a page that just shows how bad JSP really is. Even combined
with nice toolsets like Struts, it still sucks.
thanks,
-jon
--
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/> | <http://java.apache.org/turbine/>
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/[email protected]/>
List Help?: [EMAIL PROTECTED]