Re: Escapng problem

2005-12-07 Thread apache
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

Re: Disable echo in VTL

2006-02-07 Thread apache
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

Re: Can we use File object in VTL?

2006-02-07 Thread apache
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

Re: Can we use File object in VTL?

2006-02-08 Thread apache
. 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

Re: flushing a context

2006-02-09 Thread apache
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

Re: How to escape formal reference notation ?

2006-02-16 Thread apache
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.

Re: #macro recursion

2006-03-09 Thread apache
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 ) ...

Re: one question

2006-03-20 Thread apache
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 !

Re: How to stop a loop (#foreach)

2006-03-23 Thread apache
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

Re: DateTool and human-friendly date formats

2006-04-28 Thread apache
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

Re: Nested, cartesian loop of dynamic values

2006-05-12 Thread apache
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

Re: How can I trimming $string ?

2006-05-19 Thread apache
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:

Re: Global variables

2006-05-31 Thread apache
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

Re: The role of filename-extensions in velocity development

2006-06-22 Thread apache
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

Re: String to int

2006-07-06 Thread apache
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 =

Re: Putting key/value pair into hashmap from velocity template

2006-07-19 Thread apache
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

Re: Overriding the default precedence of the template engine

2006-07-21 Thread apache
. 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

Re: Putting key/value pair into hashmap from velocity template

2006-07-21 Thread apache
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

Re: Mistake

2006-09-26 Thread apache
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

Re: simple question

2006-10-11 Thread apache
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

Re: simple question 2

2006-10-11 Thread apache
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