Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Velocity Wiki" for 
change notification.

The "VelocityFAQ" page has been changed by ClaudeBrisson:
https://wiki.apache.org/velocity/VelocityFAQ?action=diff&rev1=37&rev2=38

   * A: Exactly where you put the closing braces in java.  So your example 
would be "#if( $a )#if( $b ) b1 #else b2 #end #if( $c ) c1 #else c2 #end#end".  
Pretty easy.
  <<BR>>
   * Q: Adding ## at the end of a template causes a parsing exception, what do 
I do?
-  * A: For now, a workaround is: add a newline to the end of the file.
+  * A: A workaround is: add a newline to the end of the file. This issue has 
been fixed in Velocity 2.x.
  <<BR>>
   * Q: Can velocity render 'dynamic properties' like #set ($bar = "name") 
$foo.$bar ?
-  * A: Not directly, but possible using !RenderTool or !ViewRenderTool in 
VelocityTools, Or a custom tool can be written using Velocity.evaluate(...).
+  * A: You can do so using the #evaluate() directive:
+ {{{
+   #set($bar = 'name')
+   #set($var = '$foo') ## a string in single quotes is not interpolated
+   #evaluate("${var}.$bar")
+ }}}
+ You can also check the !RenderTool or !ViewRenderTool in VelocityTools, which 
offers some flexibility on which context to use in the evaluation, or write a 
custom tool using Velocity.evaluate(...).
  <<BR>>
   * Q: How do I output values from a hash when I do not know the keys?
   * A: Easy - remember, the context has real java objects, all public methods 
can be used.
@@ -38, +44 @@

   * A: See CheckingForNull
  <<BR>>
   * Q: I want to do a "silent" #parse/#include
-  * A: You can apply the patch at 
[[http://issues.apache.org/bugzilla/show_bug.cgi?id=28388|Bugzilla 28388]], or 
try the solution provided by Fred Toth using a combination of a tool and a 
macro.  See 
[[http://mail-archives.apache.org/mod_mbox/jakarta-velocity-user/200405.mbox/%[email protected]%3e|the
 mail archive]] for details.
+  * A: You can try the solution provided by Fred Toth using a combination of a 
tool and a macro.  See 
[[http://mail-archives.apache.org/mod_mbox/jakarta-velocity-user/200405.mbox/%[email protected]%3e|the
 mail archive]] for details.
  
   * Q: Fred Toth's solution doesn't work for VelocityTools 1.2.  :(
   * A: From 1.2, !VelocityViewServlet uses the !SeparateInstanceModel.  You 
will have to set the !VelocityEngine instead of the Velocity singleton class.  
Something like SilentParseInclude.
@@ -47, +53 @@

   * A: Velocity runs on the '''server''', whereas !JavaScript runs on the 
'''client''' in the browser. Examples: a user requests a page, on the server 
Velocity renders templates into HTML which is sent to the browser to display. 
All of the Velocity template processing happens '''before''' the page is sent 
to the browser. There is no way for !JavaScript to render Velocity template 
directives without going BACK to the server. Note also that Velocity '''can''' 
be used to render custom !JavaScript. (Tim Colson) 
  <<BR>>
   * Q: How can i lower memory usage by Velocity?
-  * A: If you have no concerns about speed, the easiest thing is to just turn 
off template caching. This can be done by setting {{{<resource loader 
name>.resource.loader.cache = false}}} (see 
[[http://jakarta.apache.org/velocity/docs/developer-guide.html#Configuring%20Resource%20Loaders|Configuring
 Resource Loaders]]).  If you still want to maintain some level of caching, try 
upgrading to Velocity 1.5 which uses an LRUMap for template caching.  This 
allows you to limit caching to any specified number of your most used 
templates.  Just set {{{resource.manager.defaultcache.size=<some number>}}}.  
It is also possible to create your own custom !ResourceCache and plug that in 
instead of the default cache.
+  * A: If you have no concerns about speed, the easiest thing is to just turn 
off template caching. This can be done by setting {{{<resource loader 
name>.resource.loader.cache = false}}} (see 
[[http://velocity.apache.org/engine/2.0/configuration.html#resource-management|Resource
 Management]]).  If you still want to maintain some level of caching, since 
Velocity uses an LRUMap for template caching, you can limit caching to any 
specified number of your most used templates.  Just set 
{{{resource.manager.defaultcache.size=<some number>}}}.  It is also possible to 
create your own custom !ResourceCache and plug that in instead of the default 
cache.
  
  If none of these tweaks work for you here are a few more tips:
  

Reply via email to