Jari Worsley wrote:
> 
> "Geir Magnusson Jr." wrote:
> >
> >
> > If there is functionality from an existing commons component that can be
> > leveraged, it will be done.  Right now there are no tools that will add
> > two floating point numbers, for example, but it is something that people
> > want to do when using Velocity and WebMacro.  We believe that it's not
> > appropriate to be in the template language proper (just as it isn't in
> > JSP proper...), so custom tools are the solution.
> 
> As an aside, for floating point math, what's wrong with the java.math
> package? and using BigDecimal and BigInteger?

The short answer is "Nothing, really, except that it's a narrowly
defined API".

The real answer assumes a little about how things like Velocity work.
See below.
 
> Or am i missing something.

The question is how do you access it?  And for this game, you can't use
scriptlets in JSP :)

In velocity, we never allow 'new' from a template to prevent trouble. It
also keeps the designer from having to know about the Java API - tools
are provided.  Some of those tools could be JDK classes, but people tend
to make them easier to use by wrapping them.

The controller servlet places all allowed tools in the 'context' that
the template can access, something like

context.put("mathtool", new MathTool() );

and then in the template, you can use it.

$mathtool.mul( $a, $b )

and if the MathTool was generously written, then mul() would handle
different types of input for $a and $b, and deal with them if possible.  

This moves the onus of understanding the Java API's back onto the
programmer, and not the designer.

So in short, that is why people make and use tools like this.  I guess
the math example is pushing it, because as you note, there are classes
to do that, but there is room for enhancement for convenience.

geir

-- 
Geir Magnusson Jr.                           [EMAIL PROTECTED]
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
You have a genius for suggesting things I've come a cropper with!

Reply via email to