You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Tal Dayan <ta...@zapta.com> on 2001/07/24 05:05:27 UTC

Documentation bug and more

The example at
http://jakarta.apache.org/velocity/user-guide.html#Conditionals

#elseif( $bar = 6 )

seems to be incorrect. For a proper numeric comparison, it should be '=='
not '='. At
least this is what we figured our at the end of a long day. Also, the
following documentation
regarding the '==' as the identity misled us since it is not the case when
you compare
numeric values (which are represented by Integer instances) which means that
($foo == 5) is
different from ($foo == $bar) even if $bar is set to 5. Am I missing
somthing ?

This raises again the issue of handling errors in the template.

Velocity seems to be very casual about errors (or at least
'misunderstandings') in the template
which makes it difficult to debug or test new templates. The other case we
encountered was
when we the number we used in the comparison was a Long rather than an
Integer. Between these
two cases, we (that is, I) spent significant time to figure out what is
going wrong and had to resort
to consulting the source code.

Is there any way to make velocity more helpful in similar situations ? If it
already spits
errors or warning to a log file, is it possibly to make them more visible ?
If it ignore these
cases, is it possible to make it more strict (even a runtime flag that sets
the levels or
errors/warning reporting).

BTW, we are using it from an application, not as a servlet.

Thanks for a great product,

Tal



Re: Documentation bug and more

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tal Dayan wrote:
> 
> > Is this a commercial product? If so, can it be mentioned on the
> > powered-by page?  (Where we brag...)
> >
> >
> > geir
> >
> 
> Yes, but I am not sure that they will want to expose it since they work in
> stealth mode. I will check it with them.
> 
> I am involved in another commercial product, (Ontero InfoCentral from Ontero
> Inc, a zero administration
> Intranet solution, www.ontero.com). We are now in the process of integrating
> velocity in it.
> 
> In the first phase Velocity will be used for peripheral facilities, one is
> to generate
> at runtime a server.xml configuration for Tomcat and the other is a mail
> template. Later
> we will consider using it also in the publishing engine.
> 
> If you think this qualifies it for the Velocity 'seal', we may add it to the
> Velocity site.

Anything that uses Velocity is interesting!

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

RE: Documentation bug and more

Posted by Tal Dayan <ta...@zapta.com>.

> Is this a commercial product? If so, can it be mentioned on the
> powered-by page?  (Where we brag...)
>
>
> geir
>

Yes, but I am not sure that they will want to expose it since they work in
stealth mode. I will check it with them.

I am involved in another commercial product, (Ontero InfoCentral from Ontero
Inc, a zero administration
Intranet solution, www.ontero.com). We are now in the process of integrating
velocity in it.

In the first phase Velocity will be used for peripheral facilities, one is
to generate
at runtime a server.xml configuration for Tomcat and the other is a mail
template. Later
we will consider using it also in the publishing engine.

If you think this qualifies it for the Velocity 'seal', we may add it to the
Velocity site.

Tal


Re: Documentation bug and more

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tal Dayan wrote:
> 
> Hi Gier,
> 
> >
> > Nope.  Thanks.  I fixed the typo, and claified the following text.
> 
> Thanks, it looks good. You may want to clarify also the semantic of the '=='
> operator.
> Does it uses the Java 'equals' method, the identity operator, or both,
> depending on the
> context ?

Equals - that's a good point...

> 
> Take for example the following case:
> 
> $s1 <-  new String("a")
> $s2 <-  new String("a")
> 
> $i1 <-  new Integer(1)
> $i2 <-  new Integer(1)
> 
> $f1 <-  new Float(1.0)
> $f2 <-  new Float(1.0)
> 
> What will be the value of the conditions:
> 
> ($s1 == $s2)   // false ?
> 
> ($i1 == $i2)   // true  ?
> 
> ($f1 == $f2)   // false ?

Yep - would be good to illustrate that as well.
 
> > > This raises again the issue of handling errors in the template.
> > >
> > > Velocity seems to be very casual about errors (or at least
> > > 'misunderstandings') in the template
> > > which makes it difficult to debug or test new templates. The
> > other case we
> > > encountered was
> > > when we the number we used in the comparison was a Long rather than an
> > > Integer. Between these
> > > two cases, we (that is, I) spent significant time to figure out what is
> > > going wrong and had to resort
> > > to consulting the source code.
> >
> > Did you consult the log?  It should have listed something like -
> >
> > Tue Jul 24 06:27:26 EDT 2001  [error] Error in evaluation of ==
> > expression. Both arguments must be of the same Class. Currently left =
> > class java.lang.Long, right = class java.lang.Integer. tal.vm [line 3,
> > column 16] (ASTEQNode)
> 
> This looks like a great error diagnostic. I should check the log.
> The point is that the log is not that visible, at least when you embed an
> out of the box Velocity in an existing application.
> 
> How about making the error messages more 'in your face'. For example by
> sending the
> log to the standard output or even throwing an exception.

Not a chance :)

It would get lost to std out, and an exception would be horrendous (in
my opinion).

What you can do, if you like, is implement a logger, and hand that to
velocity.  Velocity's logging system is quite simple and extensable -
you can make your own logger class, or even hand it a living object that
supports the right interface to use for logging.

See the logger example, as well as the ExternalLoggerTest in o.a.v.test

Once you have your own logging class, you can throw exceptions to your
hearts delight...

> 
> > > BTW, we are using it from an application, not as a servlet.
> > >
> >
> > Cool.  What does it do? (I love hearing about the app uses...)
> 
> Velocity saved us a lot of development time and is much better than
> anything we could budget its developement.
> 
> The application is a web based CRM product of a client of mine. They need to
> send email
> messages when certain events are past due so we use a velocity template to
> customize the email messages.

Coolness and beauty.
 
> There are few features of Velocity that helped us doing so:
> 
> 1. The ability to return values back to the Java code. The email template
> uses this to control various email fields (to, cc, subject, etc) not just
> the message body. Otherwise
> we would have to use a template for each field or use a kludge that extracts
> the fields values form the text genrated by the template.
> 
> 2. The ability to pass and access beans. Since the system already
> had beans for User, Acount, etc, we are just passing them to the template
> and all data
> is immedietly available to the tmeplate with virtually zero development (on
> our side ;-) ).
> 
> 3. The ability to isolate the template from the rest of the Java code. With
> JSP, a
> template writer has full access to the Java VM and can modify global values,
> write
> to files, etc. We need to have a stricter control for security and
> maintenance reasons.
> 
> 4. Ease of integration. It took us only few hours for the first activation
> of a simple
> template.
> 
> The introduction of Velocity to that project was a great success and they
> are considering
> using it for other purposes.

Is this a commercial product? If so, can it be mentioned on the
powered-by page?  (Where we brag...)
 

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

Re: Documentation bug and more

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tal Dayan wrote:
> 
> I don't get any error or warning for the following:
> 
> #if ($day = 3)
> 
> #end
> 
> Isn't the assignment operator illegal here ?
> 
> If I get the Velocity Principle, shmoo is sacred but built in directives
> are open game. Following this approach, the above should generate and error.
> The same
> is $day is not an integer or undefined.
> 

Hm. Yes, that should generate an error.

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.

RE: Documentation bug and more

Posted by Tal Dayan <ta...@zapta.com>.
I don't get any error or warning for the following:

#if ($day = 3)

#end

Isn't the assignment operator illegal here ?

If I get the Velocity Principle, shmoo is sacred but built in directives
are open game. Following this approach, the above should generate and error.
The same
is $day is not an integer or undefined.

Tal



> -----Original Message-----
> From: Barbara Baughman [mailto:baughman@utdallas.edu]
> Sent: Tuesday, July 24, 2001 12:05 PM
> To: velocity-user@jakarta.apache.org
> Subject: RE: Documentation bug and more
>
>
> You can catch the ParseErrorException from getTemplate() and output the
> error message wherever you please, including the context.  I send mine to
> the console.
>
> I like the log as it is.
>
> Barbara Baughman
> X2157
>
> On Tue, 24 Jul 2001, Tal Dayan wrote:
>
> > > > This raises again the issue of handling errors in the template.
> > > >
> > > > Velocity seems to be very casual about errors (or at least
> > > > 'misunderstandings') in the template
> > > > which makes it difficult to debug or test new templates. The
> > > other case we
> > > > encountered was
> > > > when we the number we used in the comparison was a Long
> rather than an
> > > > Integer. Between these
> > > > two cases, we (that is, I) spent significant time to figure
> out what is
> > > > going wrong and had to resort
> > > > to consulting the source code.
> > >
> > > Did you consult the log?  It should have listed something like -
> > >
> > > Tue Jul 24 06:27:26 EDT 2001  [error] Error in evaluation of ==
> > > expression. Both arguments must be of the same Class. Currently left =
> > > class java.lang.Long, right = class java.lang.Integer. tal.vm [line 3,
> > > column 16] (ASTEQNode)
> >
> > This looks like a great error diagnostic. I should check the log.
> > The point is that the log is not that visible, at least when
> you embed an
> > out of the box Velocity in an existing application.
> >
> > How about making the error messages more 'in your face'. For example by
> > sending the
> > log to the standard output or even throwing an exception.
>
>


RE: Documentation bug and more

Posted by Barbara Baughman <ba...@utdallas.edu>.
You can catch the ParseErrorException from getTemplate() and output the
error message wherever you please, including the context.  I send mine to
the console.

I like the log as it is.

Barbara Baughman
X2157

On Tue, 24 Jul 2001, Tal Dayan wrote:

> > > This raises again the issue of handling errors in the template.
> > >
> > > Velocity seems to be very casual about errors (or at least
> > > 'misunderstandings') in the template
> > > which makes it difficult to debug or test new templates. The
> > other case we
> > > encountered was
> > > when we the number we used in the comparison was a Long rather than an
> > > Integer. Between these
> > > two cases, we (that is, I) spent significant time to figure out what is
> > > going wrong and had to resort
> > > to consulting the source code.
> >
> > Did you consult the log?  It should have listed something like -
> >
> > Tue Jul 24 06:27:26 EDT 2001  [error] Error in evaluation of ==
> > expression. Both arguments must be of the same Class. Currently left =
> > class java.lang.Long, right = class java.lang.Integer. tal.vm [line 3,
> > column 16] (ASTEQNode)
> 
> This looks like a great error diagnostic. I should check the log.
> The point is that the log is not that visible, at least when you embed an
> out of the box Velocity in an existing application.
> 
> How about making the error messages more 'in your face'. For example by
> sending the
> log to the standard output or even throwing an exception.


RE: Documentation bug and more

Posted by Tal Dayan <ta...@zapta.com>.
Hi Gier,

>
> Nope.  Thanks.  I fixed the typo, and claified the following text.

Thanks, it looks good. You may want to clarify also the semantic of the '=='
operator.
Does it uses the Java 'equals' method, the identity operator, or both,
depending on the
context ?

Take for example the following case:

$s1 <-  new String("a")
$s2 <-  new String("a")

$i1 <-  new Integer(1)
$i2 <-  new Integer(1)

$f1 <-  new Float(1.0)
$f2 <-  new Float(1.0)

What will be the value of the conditions:

($s1 == $s2)   // false ?

($i1 == $i2)   // true  ?

($f1 == $f2)   // false ?

> > This raises again the issue of handling errors in the template.
> >
> > Velocity seems to be very casual about errors (or at least
> > 'misunderstandings') in the template
> > which makes it difficult to debug or test new templates. The
> other case we
> > encountered was
> > when we the number we used in the comparison was a Long rather than an
> > Integer. Between these
> > two cases, we (that is, I) spent significant time to figure out what is
> > going wrong and had to resort
> > to consulting the source code.
>
> Did you consult the log?  It should have listed something like -
>
> Tue Jul 24 06:27:26 EDT 2001  [error] Error in evaluation of ==
> expression. Both arguments must be of the same Class. Currently left =
> class java.lang.Long, right = class java.lang.Integer. tal.vm [line 3,
> column 16] (ASTEQNode)

This looks like a great error diagnostic. I should check the log.
The point is that the log is not that visible, at least when you embed an
out of the box Velocity in an existing application.

How about making the error messages more 'in your face'. For example by
sending the
log to the standard output or even throwing an exception.


> > BTW, we are using it from an application, not as a servlet.
> >
>
> Cool.  What does it do? (I love hearing about the app uses...)

Velocity saved us a lot of development time and is much better than
anything we could budget its developement.

The application is a web based CRM product of a client of mine. They need to
send email
messages when certain events are past due so we use a velocity template to
customize the email messages.

There are few features of Velocity that helped us doing so:

1. The ability to return values back to the Java code. The email template
uses this to control various email fields (to, cc, subject, etc) not just
the message body. Otherwise
we would have to use a template for each field or use a kludge that extracts
the fields values form the text genrated by the template.

2. The ability to pass and access beans. Since the system already
had beans for User, Acount, etc, we are just passing them to the template
and all data
is immedietly available to the tmeplate with virtually zero development (on
our side ;-) ).

3. The ability to isolate the template from the rest of the Java code. With
JSP, a
template writer has full access to the Java VM and can modify global values,
write
to files, etc. We need to have a stricter control for security and
maintenance reasons.

4. Ease of integration. It took us only few hours for the first activation
of a simple
template.

The introduction of Velocity to that project was a great success and they
are considering
using it for other purposes.

My next usage of Velocity (for a different organization) will be a dynamic
generation of configuration
files. One of the problem we have with Tomcat (standalone mode) is that the
port on which
it listens on is hard coded in server.xml. For various reasons we need
something more
flexible that can be determined in the command line (e.g. -htt_port
80 -ajp_port 8007) so
we plan to write a wrapper around Tomcat startup that will use Velocity to
generate
the server.xml from a template. It would be nice if Tomcat would support
Velocity in the various
configuration files and will allow to use system properties and command line
arguments
as Velocity variables.

Velocity rocks !

Tal

>
> geir
>
> --
> Geir Magnusson Jr.                           geirm@optonline.net
> System and Software Consulting
> Developing for the web?  See http://jakarta.apache.org/velocity/
> Be well, do good work, and keep in touch.
>


Re: Documentation bug and more

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
Tal Dayan wrote:
> 
> The example at
> http://jakarta.apache.org/velocity/user-guide.html#Conditionals
> 
> #elseif( $bar = 6 )
> 
> seems to be incorrect. For a proper numeric comparison, it should be '=='
> not '='. At
> least this is what we figured our at the end of a long day. Also, the
> following documentation
> regarding the '==' as the identity misled us since it is not the case when
> you compare
> numeric values (which are represented by Integer instances) which means that
> ($foo == 5) is
> different from ($foo == $bar) even if $bar is set to 5. Am I missing
> somthing ?
> 

Nope.  Thanks.  I fixed the typo, and claified the following text.

> This raises again the issue of handling errors in the template.
> 
> Velocity seems to be very casual about errors (or at least
> 'misunderstandings') in the template
> which makes it difficult to debug or test new templates. The other case we
> encountered was
> when we the number we used in the comparison was a Long rather than an
> Integer. Between these
> two cases, we (that is, I) spent significant time to figure out what is
> going wrong and had to resort
> to consulting the source code.

Did you consult the log?  It should have listed something like -

Tue Jul 24 06:27:26 EDT 2001  [error] Error in evaluation of ==
expression. Both arguments must be of the same Class. Currently left =
class java.lang.Long, right = class java.lang.Integer. tal.vm [line 3,
column 16] (ASTEQNode)

This issue, namely numeric comparison, is something I will get to right
after we come to some conclusion about the separate instance version of
vel that is languishing on my local machine :)

> 
> Is there any way to make velocity more helpful in similar situations ? If it
> already spits
> errors or warning to a log file, is it possibly to make them more visible ?

To whom?  Log messages, which I would argue are rather descriptive, go
to the log file under [error], so you could always grep for that to
avoid reading through all the goop.

> If it ignore these
> cases, is it possible to make it more strict (even a runtime flag that sets
> the levels or
> errors/warning reporting).

It's *very* strict right now, and logs as such.  
 
> BTW, we are using it from an application, not as a servlet.
> 

Cool.  What does it do? (I love hearing about the app uses...)

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
Be well, do good work, and keep in touch.