You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by sri dhar <sr...@rediffmail.com> on 2004/11/23 10:29:48 UTC

I have a doubt, how to integrate the Math Tool and how to use it in velocity .vm page?

  

Hi EveryBody,
I have a doubt, how to integrate the Math Tool and how to use it in velocity .vm page?
Procedure that i have done are follows...
1.In web.xml i have added these lines of code
<init-param>
  <param-name>org.apache.velocity.toolbox</param-name>
  <param-value>/WEB-INF/toolbox.xml</param-value>
</init-param>
2.i have added one more file toolbox.xml in /web-inf
<?xml version="1.0"?>

<toolbox> 
<tool>
<key>math</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.MathTool</class>
</tool>

<tool>
<key>toolLoader</key>
<class>org.apache.velocity.tools.generic.ToolLoader</class>
</tool>
</toolbox> 

3.in file.vm i'm using this syntax
#set($math = $webwork.bean("org.apache.velocity.tools.generic.MathTool")) 

$toolLoader.load("math", "org.apache.velocity.tools.generic.MathTool")
$math.random(1,1000)
#set($x="7.8989")
$math.roundTo(2,$x);
4. i have added the jar file velocity-tools-1.1.jar in lib folder and set the classpath, still the vm file is not working.

So what to do?
How to solve this problem.

Regds
Sridhar

Re: I have a doubt, how to integrate the Math Tool and how to use it in velocity .vm page?

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Sridhar,

> I have a doubt, how to integrate the Math Tool and how to use it in velocity .vm page?

I am assuming you are using VelocityViewServlet.
  http://jakarta.apache.org/velocity/tools/view/

> Procedure that i have done are follows...

## snip

> 2.i have added one more file toolbox.xml in /web-inf

## snip

> <tool>
> <key>toolLoader</key>
> <class>org.apache.velocity.tools.generic.ToolLoader</class>
> </tool>
> </toolbox>

Actually, ToolLoader is deprecated, and you don't even need to use it.
  http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/ToolLoader.html

> 3.in file.vm i'm using this syntax
> #set($math = $webwork.bean("org.apache.velocity.tools.generic.MathTool"))
> 
> $toolLoader.load("math", "org.apache.velocity.tools.generic.MathTool")
> $math.random(1,1000)
> #set($x="7.8989")
> $math.roundTo(2,$x);

Once you define MathTool in toolbox.xml (step 2), it will be available
as $math.  So there is no need to #set($math = ...) or to use
ToolLoader.  Just go on and $math.random(...).  ;)

> 4. i have added the jar file velocity-tools-1.1.jar in lib folder and set the classpath, still the vm file is not working.

Good luck!

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

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