The formal reference notation ${foo} is hopefully a good
workaround to make it work:
#set( $d = '$' )
arg1value=${d}{var:maxlength}
It seems to me you found two related bugs in the parser.
a) Trying to parse something that is not a real reference (starting
with ${ and contining a :) and
I used a macro for this purpose
##
## convenience directive to invoke a method and ignore the return value
##
#macro( call $foo )#if($foo)#**##end#end
Hi Anagha,
I sometimes use velocity to generate diverse ASCII files from
CSV or other inputs. I use my own TemplateTool that has some
few goodies in the context - like the ClassTool used in the macro
below.
##
## Macro to
. I don't know if these will go
through the mailing list...
Look for another ClassUtils in the current velocity source tree, or
take it from the SVN repository:
http://svn.apache.org/repos/asf/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/util/ClassUtils.java
Too bad this class has
Velocity allows context chaining, see:
http://jakarta.apache.org/velocity/docs/developer-guide.html#Context%20Chaining
The overlay context can be cleared or discarded on
discretion of the application.
In an early application of mine, I used a servlet with a
base context with constants and
Use velocity's form of poor man's escaping, which will always work:
#set ($D = '$' )
${D}{javadoc.${set}.title}
will then properly output: ${javadoc.foo.title} as you desired.
If you have the EscapeTool in the context (from VelocityTools)
$esc.d{javadoc.${set}.title}
Cheers,
Christoph
P.S.
Macro recursion works, but beware that velocity passes
parameters as references to the original context - which
means that changing this variable within the macro
changes it for the caller.
So recurse with depth first is tricky or imposible:
#macro( myMacro $foo )
#myMacro( $foo + 1 )
...
I strongly recommend using a token instead of
escaping:
If you want to render:
$!foo
do:
#set( $D = '$' )
${D}!foo
and you completely avoided a reference to $foo ,
which would render differently if it is defined
or not.
Cheers,
Christoph
吴耀华 wrote:
Advanced Issues: Escaping and !
You should consider using the IteratorTool, look at
the documentation at:
http://jakarta.apache.org/velocity/tools/generic/
Cheers,
Christoph
Pham Anh Tuan wrote:
Hi all,
I don't know how we can stop a loop or #foreach?
help me plz
thanks in advance
bowlkhin
Hi Chris,
this seems to be a classical view task. You can put
the code into a tool (possibly a subclass of DateTool);
but you can also accommodate such a thing in a macro.
I have done something similar (OK, not the cleanest approach,
but it works. Part of this could have been done with the
Claude pointed already in the right direction.
Your inquiry is clear enough to give a concrete
(untested) code snippet using the RenderTool:
#foreach ($function in $functions)
#foreach ($parameter in $parameters)
$render.eval($ctx, ${object}.${function}(${parameter}))
#end
#end
Your
Hi,
this is a typical whitespace issue. Please note that
Velocity mostly leaves the whitespaces you coded in
your template. Many times it would be desirable to
be able to add indented markup without introducing
spacing and formatting artifacts. This issue is
under discussion in the wiki page:
Hi,
Daniel Pfeifer wrote:
Well, no, it really doesn't make sense why string concatenation doesn't
work ;)
Depends on from where you come and on your point of view.
The syntax for string catenation in Velocity is widely
used.
However, I'll simply do as you suggested.
/Daniel
Every
Hi,
some background of the extensions used in Velocity:
*.vm Velocity was designed to be a clean-room replacement for
WebMacro, which uses the extension *.wm.
*.vsl In analogy to *.xsl for the XSLT (XML Stylesheet
Transfromation) Velocity implemented two applications
Anakia
Use the Java Integer class as a Tool.
#set( $Integer = 1 )
#set( $myInt = $Integer.valueOf( $myNumericalString ) )
# The valueOf(...) may take a second parameter radix
# other cool method is the toHexString()
You can do the same for Long and other Number subclasses:
#set( $Long =
try without the square brackets...
;) Christoph
Matthias Hendler wrote:
Hello,
I try to put a key/value pair to a hashmap from velocity template.
First I put a new hashmap object into velocity context named myMap.
In my templates I can write:
...
$myMap.clear()
Size: $myMap.size()
...
The
. The most powerful and implicit solution is to create
your own context implementation, that takes the value from
the background ChainedContext if it is defined.
Look at the implemetnation of the AbstractContext:
http://jakarta.apache.org/velocity/docs/api/org/apache/velocity/context
Hi,
instead of doing a Map-Wrapper I always use a simple macro
to hide the output of a method call:
#macro( call $exp )#if( $exp )#**##end
...
#call( $jMap.put(ttt123,test) )
The empty comment within the if-statement is to avoid a parser
bug of early velocity versions. I do not know if the
Hi Jens,
velocity acts differently if $foo is in the context or not.
The documentation example you quoted seems to be for the
case where the key foo was in the context, in which case
the presented reply in this thread from trad-ex user is
more correct.
When $foo is not in the context I would
your string matches Velocity semantics up to the (,
and that is why the parser has trouble witch what comes
afterwards.
Just replace the initial $ to soothe the barking parser:
#set( $D = '$' )
...
${D}{loginGenerator.generateLogin(quot;Johnquot;,quot;Smithquot;)}
...
This $D form is what has
As simple as this:
#set( $products=$products,$user.productName )
See more at:
http://jakarta.apache.org/velocity/docs/user-guide.html#String%20Concatenation
I do remember having seen the +-operator implemented
for string concatenation, can someone geve me a pointer
or state if 1.5 will have
21 matches
Mail list logo