On Nov 4, 2004, at 4:07 AM, Christoph Reck wrote:

Use velocity's form of poor man's escaping, which will always work:

#set ($D = '$' )
#set( $H = '#' )
${D}sys.thing($H$H)   just a test

will then properly output:

$sys.thing(##)

I assumed that this sort of thing would work, but I fear it may be too complex for my users.
I was really hoping that the most straightforward case:


$sys.thing(#)

would just work. Since the 'thing' method can't deal with a '#' and '#)' is not a valid VTL symbol it should output the string unchanged - right? Why is the # not being spit out verbatim like it is for other input that doesn't match a VTL keyword? e.g.:

The symbol # is called an octothorpe, hash, sharp, number sign, cross-hatch, square, or pound symbol. http://www.worldwidewords.org/weirdwords/ww-oct1.htm

In any case I found this really frustrating to deal with. I think it should be handled better.

Scott Palmer wrote:
I'm new so if I just don't get it yet, sorry.
class MyObj {
public String thing( int i ) { return String.valueOf( i*i ); }
}
MyObj sysObj = new MyObj();
context.add("sys",mySysObj);
My template looks like:
$sys.thing(##) just a test
which results in a crash.
org.apache.velocity.exception.ParseErrorException: Encountered " \t" at line 18, column 11
Was expecting one of:
<EOF>
...

The parser wants the method call to be closed; but the line comment gobbled the closing bracket; therefore, the velocity construct is incomplete and the parser chokes.

But if I split that line of my template
$sys.thing(
##)  just a test

here the parser is a bit wiser, and notices that the construct is not a method call and emits the string. The closing bracket is part of the line comment and does not appear in the output.

It feels like a bug to me. Isn't the parser supposed to leave unchanged anything it can't resolve as an object in the context? In the first case above rather than throw the exception, I would expect maybe a log message and then the same as the second case - notice that it isn't really a method call. In BOTH cases there is a unclosed method call. Shouldn't an end-of-line comment and a true end of line work the same?


or if I simply move the ## over by one character
$sys.thing()##  just a test
The template is processed without any problems.  giving the output

this is 100% valid VTL!

Isn't $sys.thing(#) just as valid? Isn't # not treated special if what follows it is not a VTL keyword?


I wouldn't complain if it weren't for the fact that the reports I intend to generate with Velocity could very likely contain many '#'s in the output. It's up to my end users to build the template, and they usually have no knowledge of programming. I'm going to have to provide plenty of examples just to get them to deal with #foreach. I was thinking of telling them to always use the ${object} syntax just to avoid support issues. Hey, it would be neat if I could FORCE Velocity to require that syntax, is it possible?

Escaping with a backslash \$ only works partially in velocity.
You may call it a "broken" feature.

It certainly does require experimentation to get what you want. :)

Thanks for your help,

Scott


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to