You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Alex <al...@cieloindustries.com> on 2004/05/27 03:04:50 UTC

Velocity Bug/Inconsistency and a question

I have a Velocity script that has a lot of calls to void methods 
of  objects in my context. To format my script nicely I found that I could 
add "##" to the end of the method calls and it would suppress the new line. 
However if I end a line with "##" and the next line starts with #set, the 
#set line gets rendered as literal instead of actually setting a variable 
in the context. The same does NOT happen for #foreach, #if, etc...

Is there a better way to suppress the new line other than wrapping all of 
my calls to void methods with a #set?

Alex Figliolia


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity Bug/Inconsistency and a question

Posted by Mike Kienenberger <mk...@alaska.net>.
Christoph Reck <ap...@recks.org> wrote:
> ugh, another whitespace handling bug/inconsitency.

You can add to that never-ending list that putting "##" at the end of a 
template causes a fatal parsing error.

I didn't bother opening a bug on it since it was easier to just delete the 
trailing "##"

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity Bug/Inconsistency and a question

Posted by Christoph Reck <ap...@recks.org>.
Hi,

Nathan Bubna wrote:
> Alex said:
> 
>>I have a Velocity script that has a lot of calls to void methods
>>of  objects in my context. To format my script nicely I found that I could
>>add "##" to the end of the method calls and it would suppress the new line.
>>However if I end a line with "##" and the next line starts with #set, the
>>#set line gets rendered as literal instead of actually setting a variable
>>in the context. The same does NOT happen for #foreach, #if, etc...
> 
> 
> yeah, that's a bug.  you probably should file a bug report on it.  also, what
> version is it in?

ugh, another whitespace handling bug/inconsitency.

I strongly recommend for Vel 1.5, 1.6 or even 2.0 to redefine whitespace
handling (possilby according to my proposal).

> 
> 
>>Is there a better way to suppress the new line other than wrapping all of
>>my calls to void methods with a #set?

I defined a #call macro, but ugh, again you would need to place a ## after
its invocation to supress the NL.

#macro( call $foo )#if( $foo )#**##end#end

> 
> i dunno, but here's some off-the-cuff and untested things you might try:
> -------------------
> $object.voidMethod()##

#call( $object.voidMethod() )##

which is not much better than the direct void call. OTOH, is makes the
desired action clear. Also many times, like $hashtable.put($foo) or
$session.setAttribute($bar), the call may return the previous value
which should *not* be printed - and so the #call form is apropriate.

> 
> #set( $foo = 'bar' )
> -------------------
> $object.voidMethod()#*
> *##set( $foo = 'bar' )##
> -------------------
> #if( $object.voidMethod() )##
> #end
> #set( $foo = 'bar' )
> -------------------
> 
> just some crazy thoughts...
> 
> Nathan Bubna
> nathan@esha.com

--
Christoph


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity Bug/Inconsistency and a question

Posted by Andy Cooke <ce...@macs.hw.ac.uk>.
On Thu, 2004-05-27 at 15:58, Mike Kienenberger wrote:
> Andy Cooke <ce...@macs.hw.ac.uk> wrote:
> > I was also taken surprise the other day - don't know if it is a bug.  If
> > the last line of a (2 line) template has:
> > 
> >    #parse("index.vm") ## blah
> > 
> > 
> > I get an error message in the logs like:
> > 
> > Lexical error at line 2, column 22.  Encountered: <EOF> after : ""
> 
> 
> Yeah!  That's the exact bug I was talking about.  Velocity 1.3.1 for me.  
> (Forgot to add the version).

yes, and I'm using Velocity 1.4

Andy


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity Bug/Inconsistency and a question

Posted by Mike Kienenberger <mk...@alaska.net>.
Andy Cooke <ce...@macs.hw.ac.uk> wrote:
> I was also taken surprise the other day - don't know if it is a bug.  If
> the last line of a (2 line) template has:
> 
>    #parse("index.vm") ## blah
> 
> 
> I get an error message in the logs like:
> 
> Lexical error at line 2, column 22.  Encountered: <EOF> after : ""


Yeah!  That's the exact bug I was talking about.  Velocity 1.3.1 for me.  
(Forgot to add the version).

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity Bug/Inconsistency and a question

Posted by Andy Cooke <ce...@macs.hw.ac.uk>.
Hi there,

> > I have a Velocity script that has a lot of calls to void methods
> > of  objects in my context. To format my script nicely I found that I could
> > add "##" to the end of the method calls and it would suppress the new line.
> > However if I end a line with "##" and the next line starts with #set, the
> > #set line gets rendered as literal instead of actually setting a variable
> > in the context. The same does NOT happen for #foreach, #if, etc...
> 
> yeah, that's a bug.  you probably should file a bug report on it.  also, what
> version is it in?

I was also taken surprise the other day - don't know if it is a bug.  If
the last line of a (2 line) template has:

   #parse("index.vm") ## blah


I get an error message in the logs like:

Lexical error at line 2, column 22.  Encountered: <EOF> after : ""

cheers,

Andy Cooke

> > Is there a better way to suppress the new line other than wrapping all of
> > my calls to void methods with a #set?
> 
> i dunno, but here's some off-the-cuff and untested things you might try:
> -------------------
> $object.voidMethod()##
> 
> #set( $foo = 'bar' )
> -------------------
> $object.voidMethod()#*
> *##set( $foo = 'bar' )##
> -------------------
> #if( $object.voidMethod() )##
> #end
> #set( $foo = 'bar' )
> -------------------
> 
> just some crazy thoughts...
> 
> Nathan Bubna
> nathan@esha.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
-- 
School of Mathematical and Computer Sciences
Heriot-Watt University
Edinburgh EH14 4AS
+44 131 451 8317 (work)
+44 131 476 2731 (home)


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Velocity Bug/Inconsistency and a question

Posted by Nathan Bubna <na...@esha.com>.
Alex said:
> I have a Velocity script that has a lot of calls to void methods
> of  objects in my context. To format my script nicely I found that I could
> add "##" to the end of the method calls and it would suppress the new line.
> However if I end a line with "##" and the next line starts with #set, the
> #set line gets rendered as literal instead of actually setting a variable
> in the context. The same does NOT happen for #foreach, #if, etc...

yeah, that's a bug.  you probably should file a bug report on it.  also, what
version is it in?

> Is there a better way to suppress the new line other than wrapping all of
> my calls to void methods with a #set?

i dunno, but here's some off-the-cuff and untested things you might try:
-------------------
$object.voidMethod()##

#set( $foo = 'bar' )
-------------------
$object.voidMethod()#*
*##set( $foo = 'bar' )##
-------------------
#if( $object.voidMethod() )##
#end
#set( $foo = 'bar' )
-------------------

just some crazy thoughts...

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org