You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jason Chodakowski <ja...@hyperworx.com> on 2008/04/21 17:26:18 UTC

Issues with NumberTool?

Hello... just this morning I needed to do some "in-template" number  
formatting and pulled the VelocityTools NumberTool off the shelf. Now  
that I'm trying to use it, I'm having some issues.

First, I've got a number tool in the context  - context.put("NT", new  
NumberTool())

Next, I try to format a number in the template - #set($SW =  
$NT.format("#,##0.##", "190.00"))

The "190.00" is actually pulled from the context, but there are other  
tests ahead of this to make sure we've got a real value there. When  
the template is rendered, I get this error message:

java.io.IOException:  
org.apache.velocity.exception.MethodInvocationException: Invocation of  
method 'format' in  class org.apache.velocity.tools.generic.NumberTool  
threw exception java.lang.IllegalArgumentException: Malformed pattern  
"#," @ template.vm[57,32]
	at ...

Now what is odd about this, is that it IS a valid number format - and  
looking at the source of the NumberTool, it looks like it would just  
stuff those values into a DecimalFormat and be done with it. Is  
velocity choking because of the #-pound-signs?

I double checked my format with these lines:

DecimalFormat f = new DecimalFormat("#,##0.##");
System.out.println(f.format(190.00D));

And this produces the result I expect: "190"

Also, I do have the Locale in the context too - it's just the default  
Locale which it looks like would be picked up automatically when not  
specified so I've not tried this avenue.

Any thoughts on this?

Many thanks in advance.

J --

Re: Issues with NumberTool?

Posted by Nathan Bubna <nb...@gmail.com>.
That's a good point, but now that Velocity 1.5 allows multi-line
strings, it seems like it does make some sense to allow single-line
comments in interpolated strings.

#set( $foo = "this has multiple
line
breaks in it." )

On Mon, Apr 21, 2008 at 11:40 AM, csanders <cs...@hoovers.com> wrote:
> I agree simple is best, but I don't know if I'd write this off as 'OK'
> behavior.
>
>  In most other languages where interpolation is done in double quoted
> strings, they don't account for comments, in php:
>
>
>  $var = "Hello";
>  $string = "/* $var, World */";
>  print $string;
>
>  yields:
>
>  /* Hello, World */
>
>  I don't know of any other languages that evaluate comments like that in the
> interpolation phase.
>
>  Charlie
>
>
>
>
>
>  Jason Chodakowski wrote:
>
> > The problem occurred originally with Tools v1.3 - I noticed that this was
> old news so I updated to v1.4 and the same problem occurred - that was when
> I decided it was time for an email to the list.
> >
> > As I mentioned - single quotes to the rescue - the simple solution is the
> best.
> >
> > Cheers,
> >
> > J --
> >
> > On Apr 21, 2008, at 11:08 AM, Nathan Bubna wrote:
> >
> >
> > > Looks like it.  I'm still curious what version it was with.
> > >
> > > On Mon, Apr 21, 2008 at 9:01 AM, csanders <cs...@hoovers.com> wrote:
> > >
> > > > So what was velocity doing ?
> > > >
> > > > Some problem with pound signs in double quotes ??
> > > >
> > > >
> > > >
> > > > Jason Chodakowski wrote:
> > > >
> > > >
> > > > > Ahh - brilliant. Problem solved.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > J --
> > > > >
> > > > > On Apr 21, 2008, at 10:46 AM, Nathan Bubna wrote:
> > > > >
> > > > >
> > > > >
> > > > > > Yeah, doesn't look like NumberTool has the problem.  Velocity must
> be
> > > > > > doing something funky with those # signs. Try defining those
> strings
> > > > > > with single quotes so that they aren't interpolated.  Really, as a
> > > > > > general rule, if you don't need strings to be interpolated (parsed
> as
> > > > > > if they were mini-templates), then you should single quote them
> > > > > > instead of double quote.
> > > > > >
> > > > > > $NT.format('#,##0.##','190.0')
> > > > > >
> > > > > > And for the record, which version of Velocity is this with?
> > > > > >
> > > > > > On Mon, Apr 21, 2008 at 8:37 AM, Jason Chodakowski
> > > > > >
> > > > >
> > > > <ja...@hyperworx.com> wrote:
> > > >
> > > > >
> > > > > >
> > > > > >
> > > > > > > I should also add that I also tried this in my tests:
> > > > > > >
> > > > > > > NumberTool nt = new NumberTool();
> > > > > > > Double dbl = new Double("190.00");
> > > > > > > System.out.println(nt.format("#,##0.##", dbl));
> > > > > > >
> > > > > > > This does not produce the IOException so it seems to be an
> artifact of
> > > > > > > template rendering.
> > > > > > >
> > > > > > > Hope that helps.
> > > > > > >
> > > > > > > Thanks,
> > > > > > >
> > > > > > > J --
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > > Hello... just this morning I needed to do some "in-template"
> number
> > > > > > > >
> > > > > > > >
> > > > > > > formatting and pulled the VelocityTools NumberTool off the
> shelf. Now
> > > > > > >
> > > > > >
> > > > >
> > > > that
> > > >
> > > > >
> > > > > >
> > > > > > > I'm trying to use it, I'm having some issues.
> > > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > > First, I've got a number tool in the context  -
> context.put("NT",
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > new
> > > >
> > > > >
> > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > NumberTool())
> > > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > > Next, I try to format a number in the template - #set($SW =
> > > > > > > >
> > > > > > > >
> > > > > > > $NT.format("#,##0.##", "190.00"))
> > > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > > The "190.00" is actually pulled from the context, but there
> are
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > other
> > > >
> > > > >
> > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > tests ahead of this to make sure we've got a real value there.
> When
> > > > > > >
> > > > > >
> > > > >
> > > > the
> > > >
> > > > >
> > > > > >
> > > > > > > template is rendered, I get this error message:
> > > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > > java.io.IOException:
> > > > > > > >
> > > > > > > >
> > > > > > > org.apache.velocity.exception.MethodInvocationException:
> Invocation of
> > > > > > > method 'format' in  class
> org.apache.velocity.tools.generic.NumberTool
> > > > > > >
> > > > > >
> > > > >
> > > > threw
> > > >
> > > > >
> > > > > >
> > > > > > > exception java.lang.IllegalArgumentException: Malformed pattern
> "#," @
> > > > > > > template.vm[57,32]
> > > > > > >
> > > > > > >
> > > > > > > >    at ...
> > > > > > > >
> > > > > > > > Now what is odd about this, is that it IS a valid number
> format -
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > and
> > > >
> > > > >
> > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > looking at the source of the NumberTool, it looks like it would
> just
> > > > > > >
> > > > > >
> > > > >
> > > > stuff
> > > >
> > > > >
> > > > > >
> > > > > > > those values into a DecimalFormat and be done with it. Is
> velocity
> > > > > > >
> > > > > >
> > > > >
> > > > choking
> > > >
> > > > >
> > > > > >
> > > > > > > because of the #-pound-signs?
> > > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > > I double checked my format with these lines:
> > > > > > > >
> > > > > > > > DecimalFormat f = new DecimalFormat("#,##0.##");
> > > > > > > > System.out.println(f.format(190.00D));
> > > > > > > >
> > > > > > > > And this produces the result I expect: "190"
> > > > > > > >
> > > > > > > > Also, I do have the Locale in the context too - it's just the
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > default
> > > >
> > > > >
> > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > Locale which it looks like would be picked up automatically when
> not
> > > > > > > specified so I've not tried this avenue.
> > > > > > >
> > > > > > >
> > > > > > > >
> > > > > > > > Any thoughts on this?
> > > > > > > >
> > > > > > > > Many thanks in advance.
> > > > > > > >
> > > > > > > > J --
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > > > > > For additional commands, e-mail: user-help@velocity.apache.org
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > > > > For additional commands, e-mail: user-help@velocity.apache.org
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > > > For additional commands, e-mail: user-help@velocity.apache.org
> > > >
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > > For additional commands, e-mail: user-help@velocity.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>  For additional commands, e-mail: user-help@velocity.apache.org
>
>

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


Re: Issues with NumberTool?

Posted by csanders <cs...@hoovers.com>.
I agree simple is best, but I don't know if I'd write this off as 'OK' 
behavior.

In most other languages where interpolation is done in double quoted 
strings, they don't account for comments, in php:


$var = "Hello";
$string = "/* $var, World */";
print $string;

yields:

/* Hello, World */

I don't know of any other languages that evaluate comments like that in 
the interpolation phase.

Charlie



Jason Chodakowski wrote:
> The problem occurred originally with Tools v1.3 - I noticed that this 
> was old news so I updated to v1.4 and the same problem occurred - that 
> was when I decided it was time for an email to the list.
>
> As I mentioned - single quotes to the rescue - the simple solution is 
> the best.
>
> Cheers,
>
> J --
>
> On Apr 21, 2008, at 11:08 AM, Nathan Bubna wrote:
>
>> Looks like it.  I'm still curious what version it was with.
>>
>> On Mon, Apr 21, 2008 at 9:01 AM, csanders <cs...@hoovers.com> wrote:
>>> So what was velocity doing ?
>>>
>>> Some problem with pound signs in double quotes ??
>>>
>>>
>>>
>>> Jason Chodakowski wrote:
>>>
>>>> Ahh - brilliant. Problem solved.
>>>>
>>>> Thanks,
>>>>
>>>> J --
>>>>
>>>> On Apr 21, 2008, at 10:46 AM, Nathan Bubna wrote:
>>>>
>>>>
>>>>> Yeah, doesn't look like NumberTool has the problem.  Velocity must be
>>>>> doing something funky with those # signs. Try defining those strings
>>>>> with single quotes so that they aren't interpolated.  Really, as a
>>>>> general rule, if you don't need strings to be interpolated (parsed as
>>>>> if they were mini-templates), then you should single quote them
>>>>> instead of double quote.
>>>>>
>>>>> $NT.format('#,##0.##','190.0')
>>>>>
>>>>> And for the record, which version of Velocity is this with?
>>>>>
>>>>> On Mon, Apr 21, 2008 at 8:37 AM, Jason Chodakowski
>>> <ja...@hyperworx.com> wrote:
>>>>>
>>>>>> I should also add that I also tried this in my tests:
>>>>>>
>>>>>> NumberTool nt = new NumberTool();
>>>>>> Double dbl = new Double("190.00");
>>>>>> System.out.println(nt.format("#,##0.##", dbl));
>>>>>>
>>>>>> This does not produce the IOException so it seems to be an 
>>>>>> artifact of
>>>>>> template rendering.
>>>>>>
>>>>>> Hope that helps.
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> J --
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>> Hello... just this morning I needed to do some "in-template" number
>>>>>>>
>>>>>> formatting and pulled the VelocityTools NumberTool off the shelf. 
>>>>>> Now
>>> that
>>>>>> I'm trying to use it, I'm having some issues.
>>>>>>
>>>>>>>
>>>>>>> First, I've got a number tool in the context  - context.put("NT",
>>> new
>>>>>>>
>>>>>> NumberTool())
>>>>>>
>>>>>>>
>>>>>>> Next, I try to format a number in the template - #set($SW =
>>>>>>>
>>>>>> $NT.format("#,##0.##", "190.00"))
>>>>>>
>>>>>>>
>>>>>>> The "190.00" is actually pulled from the context, but there are
>>> other
>>>>>>>
>>>>>> tests ahead of this to make sure we've got a real value there. When
>>> the
>>>>>> template is rendered, I get this error message:
>>>>>>
>>>>>>>
>>>>>>> java.io.IOException:
>>>>>>>
>>>>>> org.apache.velocity.exception.MethodInvocationException: 
>>>>>> Invocation of
>>>>>> method 'format' in  class 
>>>>>> org.apache.velocity.tools.generic.NumberTool
>>> threw
>>>>>> exception java.lang.IllegalArgumentException: Malformed pattern 
>>>>>> "#," @
>>>>>> template.vm[57,32]
>>>>>>
>>>>>>>     at ...
>>>>>>>
>>>>>>> Now what is odd about this, is that it IS a valid number format -
>>> and
>>>>>>>
>>>>>> looking at the source of the NumberTool, it looks like it would just
>>> stuff
>>>>>> those values into a DecimalFormat and be done with it. Is velocity
>>> choking
>>>>>> because of the #-pound-signs?
>>>>>>
>>>>>>>
>>>>>>> I double checked my format with these lines:
>>>>>>>
>>>>>>> DecimalFormat f = new DecimalFormat("#,##0.##");
>>>>>>> System.out.println(f.format(190.00D));
>>>>>>>
>>>>>>> And this produces the result I expect: "190"
>>>>>>>
>>>>>>> Also, I do have the Locale in the context too - it's just the
>>> default
>>>>>>>
>>>>>> Locale which it looks like would be picked up automatically when not
>>>>>> specified so I've not tried this avenue.
>>>>>>
>>>>>>>
>>>>>>> Any thoughts on this?
>>>>>>>
>>>>>>> Many thanks in advance.
>>>>>>>
>>>>>>> J --
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>>>> For additional commands, e-mail: user-help@velocity.apache.org
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>>> For additional commands, e-mail: user-help@velocity.apache.org
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>> For additional commands, e-mail: user-help@velocity.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>


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


Re: Issues with NumberTool?

Posted by Jason Chodakowski <ja...@hyperworx.com>.
The problem occurred originally with Tools v1.3 - I noticed that this  
was old news so I updated to v1.4 and the same problem occurred - that  
was when I decided it was time for an email to the list.

As I mentioned - single quotes to the rescue - the simple solution is  
the best.

Cheers,

J --

On Apr 21, 2008, at 11:08 AM, Nathan Bubna wrote:

> Looks like it.  I'm still curious what version it was with.
>
> On Mon, Apr 21, 2008 at 9:01 AM, csanders <cs...@hoovers.com>  
> wrote:
>> So what was velocity doing ?
>>
>> Some problem with pound signs in double quotes ??
>>
>>
>>
>> Jason Chodakowski wrote:
>>
>>> Ahh - brilliant. Problem solved.
>>>
>>> Thanks,
>>>
>>> J --
>>>
>>> On Apr 21, 2008, at 10:46 AM, Nathan Bubna wrote:
>>>
>>>
>>>> Yeah, doesn't look like NumberTool has the problem.  Velocity  
>>>> must be
>>>> doing something funky with those # signs. Try defining those  
>>>> strings
>>>> with single quotes so that they aren't interpolated.  Really, as a
>>>> general rule, if you don't need strings to be interpolated  
>>>> (parsed as
>>>> if they were mini-templates), then you should single quote them
>>>> instead of double quote.
>>>>
>>>> $NT.format('#,##0.##','190.0')
>>>>
>>>> And for the record, which version of Velocity is this with?
>>>>
>>>> On Mon, Apr 21, 2008 at 8:37 AM, Jason Chodakowski
>> <ja...@hyperworx.com> wrote:
>>>>
>>>>> I should also add that I also tried this in my tests:
>>>>>
>>>>> NumberTool nt = new NumberTool();
>>>>> Double dbl = new Double("190.00");
>>>>> System.out.println(nt.format("#,##0.##", dbl));
>>>>>
>>>>> This does not produce the IOException so it seems to be an  
>>>>> artifact of
>>>>> template rendering.
>>>>>
>>>>> Hope that helps.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> J --
>>>>>
>>>>>
>>>>>
>>>>> On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:
>>>>>
>>>>>
>>>>>
>>>>>> Hello... just this morning I needed to do some "in-template"  
>>>>>> number
>>>>>>
>>>>> formatting and pulled the VelocityTools NumberTool off the  
>>>>> shelf. Now
>> that
>>>>> I'm trying to use it, I'm having some issues.
>>>>>
>>>>>>
>>>>>> First, I've got a number tool in the context  - context.put("NT",
>> new
>>>>>>
>>>>> NumberTool())
>>>>>
>>>>>>
>>>>>> Next, I try to format a number in the template - #set($SW =
>>>>>>
>>>>> $NT.format("#,##0.##", "190.00"))
>>>>>
>>>>>>
>>>>>> The "190.00" is actually pulled from the context, but there are
>> other
>>>>>>
>>>>> tests ahead of this to make sure we've got a real value there.  
>>>>> When
>> the
>>>>> template is rendered, I get this error message:
>>>>>
>>>>>>
>>>>>> java.io.IOException:
>>>>>>
>>>>> org.apache.velocity.exception.MethodInvocationException:  
>>>>> Invocation of
>>>>> method 'format' in  class  
>>>>> org.apache.velocity.tools.generic.NumberTool
>> threw
>>>>> exception java.lang.IllegalArgumentException: Malformed pattern  
>>>>> "#," @
>>>>> template.vm[57,32]
>>>>>
>>>>>>     at ...
>>>>>>
>>>>>> Now what is odd about this, is that it IS a valid number format -
>> and
>>>>>>
>>>>> looking at the source of the NumberTool, it looks like it would  
>>>>> just
>> stuff
>>>>> those values into a DecimalFormat and be done with it. Is velocity
>> choking
>>>>> because of the #-pound-signs?
>>>>>
>>>>>>
>>>>>> I double checked my format with these lines:
>>>>>>
>>>>>> DecimalFormat f = new DecimalFormat("#,##0.##");
>>>>>> System.out.println(f.format(190.00D));
>>>>>>
>>>>>> And this produces the result I expect: "190"
>>>>>>
>>>>>> Also, I do have the Locale in the context too - it's just the
>> default
>>>>>>
>>>>> Locale which it looks like would be picked up automatically when  
>>>>> not
>>>>> specified so I've not tried this avenue.
>>>>>
>>>>>>
>>>>>> Any thoughts on this?
>>>>>>
>>>>>> Many thanks in advance.
>>>>>>
>>>>>> J --
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>>> For additional commands, e-mail: user-help@velocity.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>> For additional commands, e-mail: user-help@velocity.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org


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


Re: Issues with NumberTool?

Posted by Nathan Bubna <nb...@gmail.com>.
Looks like it.  I'm still curious what version it was with.

On Mon, Apr 21, 2008 at 9:01 AM, csanders <cs...@hoovers.com> wrote:
> So what was velocity doing ?
>
>  Some problem with pound signs in double quotes ??
>
>
>
>  Jason Chodakowski wrote:
>
> > Ahh - brilliant. Problem solved.
> >
> > Thanks,
> >
> > J --
> >
> > On Apr 21, 2008, at 10:46 AM, Nathan Bubna wrote:
> >
> >
> > > Yeah, doesn't look like NumberTool has the problem.  Velocity must be
> > > doing something funky with those # signs. Try defining those strings
> > > with single quotes so that they aren't interpolated.  Really, as a
> > > general rule, if you don't need strings to be interpolated (parsed as
> > > if they were mini-templates), then you should single quote them
> > > instead of double quote.
> > >
> > > $NT.format('#,##0.##','190.0')
> > >
> > > And for the record, which version of Velocity is this with?
> > >
> > > On Mon, Apr 21, 2008 at 8:37 AM, Jason Chodakowski
> <ja...@hyperworx.com> wrote:
> > >
> > > > I should also add that I also tried this in my tests:
> > > >
> > > > NumberTool nt = new NumberTool();
> > > > Double dbl = new Double("190.00");
> > > > System.out.println(nt.format("#,##0.##", dbl));
> > > >
> > > > This does not produce the IOException so it seems to be an artifact of
> > > > template rendering.
> > > >
> > > > Hope that helps.
> > > >
> > > > Thanks,
> > > >
> > > > J --
> > > >
> > > >
> > > >
> > > > On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:
> > > >
> > > >
> > > >
> > > > > Hello... just this morning I needed to do some "in-template" number
> > > > >
> > > > formatting and pulled the VelocityTools NumberTool off the shelf. Now
> that
> > > > I'm trying to use it, I'm having some issues.
> > > >
> > > > >
> > > > > First, I've got a number tool in the context  - context.put("NT",
> new
> > > > >
> > > > NumberTool())
> > > >
> > > > >
> > > > > Next, I try to format a number in the template - #set($SW =
> > > > >
> > > > $NT.format("#,##0.##", "190.00"))
> > > >
> > > > >
> > > > > The "190.00" is actually pulled from the context, but there are
> other
> > > > >
> > > > tests ahead of this to make sure we've got a real value there. When
> the
> > > > template is rendered, I get this error message:
> > > >
> > > > >
> > > > > java.io.IOException:
> > > > >
> > > > org.apache.velocity.exception.MethodInvocationException: Invocation of
> > > > method 'format' in  class org.apache.velocity.tools.generic.NumberTool
> threw
> > > > exception java.lang.IllegalArgumentException: Malformed pattern "#," @
> > > > template.vm[57,32]
> > > >
> > > > >      at ...
> > > > >
> > > > > Now what is odd about this, is that it IS a valid number format -
> and
> > > > >
> > > > looking at the source of the NumberTool, it looks like it would just
> stuff
> > > > those values into a DecimalFormat and be done with it. Is velocity
> choking
> > > > because of the #-pound-signs?
> > > >
> > > > >
> > > > > I double checked my format with these lines:
> > > > >
> > > > > DecimalFormat f = new DecimalFormat("#,##0.##");
> > > > > System.out.println(f.format(190.00D));
> > > > >
> > > > > And this produces the result I expect: "190"
> > > > >
> > > > > Also, I do have the Locale in the context too - it's just the
> default
> > > > >
> > > > Locale which it looks like would be picked up automatically when not
> > > > specified so I've not tried this avenue.
> > > >
> > > > >
> > > > > Any thoughts on this?
> > > > >
> > > > > Many thanks in advance.
> > > > >
> > > > > J --
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > > For additional commands, e-mail: user-help@velocity.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>  For additional commands, e-mail: user-help@velocity.apache.org
>
>

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


Re: Issues with NumberTool?

Posted by Nathan Bubna <nb...@gmail.com>.
oh, yeah.  single line comment.  not a bug.  that's a relief.

On Mon, Apr 21, 2008 at 9:19 AM, Jason Chodakowski <ja...@hyperworx.com> wrote:
> I think Velocity saw the double pound sign (##) and ate it... cause the
> pattern to fail. Single quotes fixed the problem.
>
>  J --
>
>
>
>  On Apr 21, 2008, at 11:01 AM, csanders wrote:
>
>
> > So what was velocity doing ?
> >
> > Some problem with pound signs in double quotes ??
> >
> > Jason Chodakowski wrote:
> >
> > > Ahh - brilliant. Problem solved.
> > >
> > > Thanks,
> > >
> > > J --
> > >
> > > On Apr 21, 2008, at 10:46 AM, Nathan Bubna wrote:
> > >
> > >
> > > > Yeah, doesn't look like NumberTool has the problem.  Velocity must be
> > > > doing something funky with those # signs. Try defining those strings
> > > > with single quotes so that they aren't interpolated.  Really, as a
> > > > general rule, if you don't need strings to be interpolated (parsed as
> > > > if they were mini-templates), then you should single quote them
> > > > instead of double quote.
> > > >
> > > > $NT.format('#,##0.##','190.0')
> > > >
> > > > And for the record, which version of Velocity is this with?
> > > >
> > > > On Mon, Apr 21, 2008 at 8:37 AM, Jason Chodakowski
> <ja...@hyperworx.com> wrote:
> > > >
> > > > > I should also add that I also tried this in my tests:
> > > > >
> > > > > NumberTool nt = new NumberTool();
> > > > > Double dbl = new Double("190.00");
> > > > > System.out.println(nt.format("#,##0.##", dbl));
> > > > >
> > > > > This does not produce the IOException so it seems to be an artifact
> of
> > > > > template rendering.
> > > > >
> > > > > Hope that helps.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > J --
> > > > >
> > > > >
> > > > >
> > > > > On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:
> > > > >
> > > > >
> > > > >
> > > > > > Hello... just this morning I needed to do some "in-template"
> number
> > > > > >
> > > > > formatting and pulled the VelocityTools NumberTool off the shelf.
> Now that
> > > > > I'm trying to use it, I'm having some issues.
> > > > >
> > > > > >
> > > > > > First, I've got a number tool in the context  - context.put("NT",
> new
> > > > > >
> > > > > NumberTool())
> > > > >
> > > > > >
> > > > > > Next, I try to format a number in the template - #set($SW =
> > > > > >
> > > > > $NT.format("#,##0.##", "190.00"))
> > > > >
> > > > > >
> > > > > > The "190.00" is actually pulled from the context, but there are
> other
> > > > > >
> > > > > tests ahead of this to make sure we've got a real value there. When
> the
> > > > > template is rendered, I get this error message:
> > > > >
> > > > > >
> > > > > > java.io.IOException:
> > > > > >
> > > > > org.apache.velocity.exception.MethodInvocationException: Invocation
> of
> > > > > method 'format' in  class
> org.apache.velocity.tools.generic.NumberTool threw
> > > > > exception java.lang.IllegalArgumentException: Malformed pattern "#,"
> @
> > > > > template.vm[57,32]
> > > > >
> > > > > >     at ...
> > > > > >
> > > > > > Now what is odd about this, is that it IS a valid number format -
> and
> > > > > >
> > > > > looking at the source of the NumberTool, it looks like it would just
> stuff
> > > > > those values into a DecimalFormat and be done with it. Is velocity
> choking
> > > > > because of the #-pound-signs?
> > > > >
> > > > > >
> > > > > > I double checked my format with these lines:
> > > > > >
> > > > > > DecimalFormat f = new DecimalFormat("#,##0.##");
> > > > > > System.out.println(f.format(190.00D));
> > > > > >
> > > > > > And this produces the result I expect: "190"
> > > > > >
> > > > > > Also, I do have the Locale in the context too - it's just the
> default
> > > > > >
> > > > > Locale which it looks like would be picked up automatically when not
> > > > > specified so I've not tried this avenue.
> > > > >
> > > > > >
> > > > > > Any thoughts on this?
> > > > > >
> > > > > > Many thanks in advance.
> > > > > >
> > > > > > J --
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > > > For additional commands, e-mail: user-help@velocity.apache.org
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > > For additional commands, e-mail: user-help@velocity.apache.org
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>  For additional commands, e-mail: user-help@velocity.apache.org
>
>

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


Re: Issues with NumberTool?

Posted by Jason Chodakowski <ja...@hyperworx.com>.
I think Velocity saw the double pound sign (##) and ate it... cause  
the pattern to fail. Single quotes fixed the problem.

J --

On Apr 21, 2008, at 11:01 AM, csanders wrote:

> So what was velocity doing ?
>
> Some problem with pound signs in double quotes ??
>
> Jason Chodakowski wrote:
>> Ahh - brilliant. Problem solved.
>>
>> Thanks,
>>
>> J --
>>
>> On Apr 21, 2008, at 10:46 AM, Nathan Bubna wrote:
>>
>>> Yeah, doesn't look like NumberTool has the problem.  Velocity must  
>>> be
>>> doing something funky with those # signs. Try defining those strings
>>> with single quotes so that they aren't interpolated.  Really, as a
>>> general rule, if you don't need strings to be interpolated (parsed  
>>> as
>>> if they were mini-templates), then you should single quote them
>>> instead of double quote.
>>>
>>> $NT.format('#,##0.##','190.0')
>>>
>>> And for the record, which version of Velocity is this with?
>>>
>>> On Mon, Apr 21, 2008 at 8:37 AM, Jason Chodakowski <jasonc@hyperworx.com 
>>> > wrote:
>>>> I should also add that I also tried this in my tests:
>>>>
>>>> NumberTool nt = new NumberTool();
>>>> Double dbl = new Double("190.00");
>>>> System.out.println(nt.format("#,##0.##", dbl));
>>>>
>>>> This does not produce the IOException so it seems to be an  
>>>> artifact of
>>>> template rendering.
>>>>
>>>> Hope that helps.
>>>>
>>>> Thanks,
>>>>
>>>> J --
>>>>
>>>>
>>>>
>>>> On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:
>>>>
>>>>
>>>>> Hello... just this morning I needed to do some "in-template"  
>>>>> number
>>>> formatting and pulled the VelocityTools NumberTool off the shelf.  
>>>> Now that
>>>> I'm trying to use it, I'm having some issues.
>>>>>
>>>>> First, I've got a number tool in the context  -  
>>>>> context.put("NT", new
>>>> NumberTool())
>>>>>
>>>>> Next, I try to format a number in the template - #set($SW =
>>>> $NT.format("#,##0.##", "190.00"))
>>>>>
>>>>> The "190.00" is actually pulled from the context, but there are  
>>>>> other
>>>> tests ahead of this to make sure we've got a real value there.  
>>>> When the
>>>> template is rendered, I get this error message:
>>>>>
>>>>> java.io.IOException:
>>>> org.apache.velocity.exception.MethodInvocationException:  
>>>> Invocation of
>>>> method 'format' in  class  
>>>> org.apache.velocity.tools.generic.NumberTool threw
>>>> exception java.lang.IllegalArgumentException: Malformed pattern  
>>>> "#," @
>>>> template.vm[57,32]
>>>>>      at ...
>>>>>
>>>>> Now what is odd about this, is that it IS a valid number format  
>>>>> - and
>>>> looking at the source of the NumberTool, it looks like it would  
>>>> just stuff
>>>> those values into a DecimalFormat and be done with it. Is  
>>>> velocity choking
>>>> because of the #-pound-signs?
>>>>>
>>>>> I double checked my format with these lines:
>>>>>
>>>>> DecimalFormat f = new DecimalFormat("#,##0.##");
>>>>> System.out.println(f.format(190.00D));
>>>>>
>>>>> And this produces the result I expect: "190"
>>>>>
>>>>> Also, I do have the Locale in the context too - it's just the  
>>>>> default
>>>> Locale which it looks like would be picked up automatically when  
>>>> not
>>>> specified so I've not tried this avenue.
>>>>>
>>>>> Any thoughts on this?
>>>>>
>>>>> Many thanks in advance.
>>>>>
>>>>> J --
>>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org


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


Re: Issues with NumberTool?

Posted by csanders <cs...@hoovers.com>.
So what was velocity doing ?

Some problem with pound signs in double quotes ??

Jason Chodakowski wrote:
> Ahh - brilliant. Problem solved.
>
> Thanks,
>
> J --
>
> On Apr 21, 2008, at 10:46 AM, Nathan Bubna wrote:
>
>> Yeah, doesn't look like NumberTool has the problem.  Velocity must be
>> doing something funky with those # signs. Try defining those strings
>> with single quotes so that they aren't interpolated.  Really, as a
>> general rule, if you don't need strings to be interpolated (parsed as
>> if they were mini-templates), then you should single quote them
>> instead of double quote.
>>
>> $NT.format('#,##0.##','190.0')
>>
>> And for the record, which version of Velocity is this with?
>>
>> On Mon, Apr 21, 2008 at 8:37 AM, Jason Chodakowski 
>> <ja...@hyperworx.com> wrote:
>>> I should also add that I also tried this in my tests:
>>>
>>> NumberTool nt = new NumberTool();
>>> Double dbl = new Double("190.00");
>>> System.out.println(nt.format("#,##0.##", dbl));
>>>
>>> This does not produce the IOException so it seems to be an artifact of
>>> template rendering.
>>>
>>> Hope that helps.
>>>
>>> Thanks,
>>>
>>> J --
>>>
>>>
>>>
>>> On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:
>>>
>>>
>>>> Hello... just this morning I needed to do some "in-template" number
>>> formatting and pulled the VelocityTools NumberTool off the shelf. 
>>> Now that
>>> I'm trying to use it, I'm having some issues.
>>>>
>>>> First, I've got a number tool in the context  - context.put("NT", new
>>> NumberTool())
>>>>
>>>> Next, I try to format a number in the template - #set($SW =
>>> $NT.format("#,##0.##", "190.00"))
>>>>
>>>> The "190.00" is actually pulled from the context, but there are other
>>> tests ahead of this to make sure we've got a real value there. When the
>>> template is rendered, I get this error message:
>>>>
>>>> java.io.IOException:
>>> org.apache.velocity.exception.MethodInvocationException: Invocation of
>>> method 'format' in  class 
>>> org.apache.velocity.tools.generic.NumberTool threw
>>> exception java.lang.IllegalArgumentException: Malformed pattern "#," @
>>> template.vm[57,32]
>>>>       at ...
>>>>
>>>> Now what is odd about this, is that it IS a valid number format - and
>>> looking at the source of the NumberTool, it looks like it would just 
>>> stuff
>>> those values into a DecimalFormat and be done with it. Is velocity 
>>> choking
>>> because of the #-pound-signs?
>>>>
>>>> I double checked my format with these lines:
>>>>
>>>> DecimalFormat f = new DecimalFormat("#,##0.##");
>>>> System.out.println(f.format(190.00D));
>>>>
>>>> And this produces the result I expect: "190"
>>>>
>>>> Also, I do have the Locale in the context too - it's just the default
>>> Locale which it looks like would be picked up automatically when not
>>> specified so I've not tried this avenue.
>>>>
>>>> Any thoughts on this?
>>>>
>>>> Many thanks in advance.
>>>>
>>>> J --
>>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>


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


Re: Issues with NumberTool?

Posted by Jason Chodakowski <ja...@hyperworx.com>.
Ahh - brilliant. Problem solved.

Thanks,

J --

On Apr 21, 2008, at 10:46 AM, Nathan Bubna wrote:

> Yeah, doesn't look like NumberTool has the problem.  Velocity must be
> doing something funky with those # signs. Try defining those strings
> with single quotes so that they aren't interpolated.  Really, as a
> general rule, if you don't need strings to be interpolated (parsed as
> if they were mini-templates), then you should single quote them
> instead of double quote.
>
> $NT.format('#,##0.##','190.0')
>
> And for the record, which version of Velocity is this with?
>
> On Mon, Apr 21, 2008 at 8:37 AM, Jason Chodakowski <jasonc@hyperworx.com 
> > wrote:
>> I should also add that I also tried this in my tests:
>>
>> NumberTool nt = new NumberTool();
>> Double dbl = new Double("190.00");
>> System.out.println(nt.format("#,##0.##", dbl));
>>
>> This does not produce the IOException so it seems to be an artifact  
>> of
>> template rendering.
>>
>> Hope that helps.
>>
>> Thanks,
>>
>> J --
>>
>>
>>
>> On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:
>>
>>
>>> Hello... just this morning I needed to do some "in-template" number
>> formatting and pulled the VelocityTools NumberTool off the shelf.  
>> Now that
>> I'm trying to use it, I'm having some issues.
>>>
>>> First, I've got a number tool in the context  - context.put("NT",  
>>> new
>> NumberTool())
>>>
>>> Next, I try to format a number in the template - #set($SW =
>> $NT.format("#,##0.##", "190.00"))
>>>
>>> The "190.00" is actually pulled from the context, but there are  
>>> other
>> tests ahead of this to make sure we've got a real value there. When  
>> the
>> template is rendered, I get this error message:
>>>
>>> java.io.IOException:
>> org.apache.velocity.exception.MethodInvocationException: Invocation  
>> of
>> method 'format' in  class  
>> org.apache.velocity.tools.generic.NumberTool threw
>> exception java.lang.IllegalArgumentException: Malformed pattern  
>> "#," @
>> template.vm[57,32]
>>>       at ...
>>>
>>> Now what is odd about this, is that it IS a valid number format -  
>>> and
>> looking at the source of the NumberTool, it looks like it would  
>> just stuff
>> those values into a DecimalFormat and be done with it. Is velocity  
>> choking
>> because of the #-pound-signs?
>>>
>>> I double checked my format with these lines:
>>>
>>> DecimalFormat f = new DecimalFormat("#,##0.##");
>>> System.out.println(f.format(190.00D));
>>>
>>> And this produces the result I expect: "190"
>>>
>>> Also, I do have the Locale in the context too - it's just the  
>>> default
>> Locale which it looks like would be picked up automatically when not
>> specified so I've not tried this avenue.
>>>
>>> Any thoughts on this?
>>>
>>> Many thanks in advance.
>>>
>>> J --
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org


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


Re: Issues with NumberTool?

Posted by Nathan Bubna <nb...@gmail.com>.
Yeah, doesn't look like NumberTool has the problem.  Velocity must be
doing something funky with those # signs. Try defining those strings
with single quotes so that they aren't interpolated.  Really, as a
general rule, if you don't need strings to be interpolated (parsed as
if they were mini-templates), then you should single quote them
instead of double quote.

$NT.format('#,##0.##','190.0')

And for the record, which version of Velocity is this with?

On Mon, Apr 21, 2008 at 8:37 AM, Jason Chodakowski <ja...@hyperworx.com> wrote:
> I should also add that I also tried this in my tests:
>
>  NumberTool nt = new NumberTool();
>  Double dbl = new Double("190.00");
>  System.out.println(nt.format("#,##0.##", dbl));
>
>  This does not produce the IOException so it seems to be an artifact of
> template rendering.
>
>  Hope that helps.
>
>  Thanks,
>
>  J --
>
>
>
>  On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:
>
>
> > Hello... just this morning I needed to do some "in-template" number
> formatting and pulled the VelocityTools NumberTool off the shelf. Now that
> I'm trying to use it, I'm having some issues.
> >
> > First, I've got a number tool in the context  - context.put("NT", new
> NumberTool())
> >
> > Next, I try to format a number in the template - #set($SW =
> $NT.format("#,##0.##", "190.00"))
> >
> > The "190.00" is actually pulled from the context, but there are other
> tests ahead of this to make sure we've got a real value there. When the
> template is rendered, I get this error message:
> >
> > java.io.IOException:
> org.apache.velocity.exception.MethodInvocationException: Invocation of
> method 'format' in  class org.apache.velocity.tools.generic.NumberTool threw
> exception java.lang.IllegalArgumentException: Malformed pattern "#," @
> template.vm[57,32]
> >        at ...
> >
> > Now what is odd about this, is that it IS a valid number format - and
> looking at the source of the NumberTool, it looks like it would just stuff
> those values into a DecimalFormat and be done with it. Is velocity choking
> because of the #-pound-signs?
> >
> > I double checked my format with these lines:
> >
> > DecimalFormat f = new DecimalFormat("#,##0.##");
> > System.out.println(f.format(190.00D));
> >
> > And this produces the result I expect: "190"
> >
> > Also, I do have the Locale in the context too - it's just the default
> Locale which it looks like would be picked up automatically when not
> specified so I've not tried this avenue.
> >
> > Any thoughts on this?
> >
> > Many thanks in advance.
> >
> > J --
> >
>
>

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


Re: Issues with NumberTool?

Posted by Jason Chodakowski <ja...@hyperworx.com>.
I should also add that I also tried this in my tests:

NumberTool nt = new NumberTool();
Double dbl = new Double("190.00");
System.out.println(nt.format("#,##0.##", dbl));

This does not produce the IOException so it seems to be an artifact of  
template rendering.

Hope that helps.

Thanks,

J --

On Apr 21, 2008, at 10:26 AM, Jason Chodakowski wrote:

> Hello... just this morning I needed to do some "in-template" number  
> formatting and pulled the VelocityTools NumberTool off the shelf.  
> Now that I'm trying to use it, I'm having some issues.
>
> First, I've got a number tool in the context  - context.put("NT",  
> new NumberTool())
>
> Next, I try to format a number in the template - #set($SW =  
> $NT.format("#,##0.##", "190.00"))
>
> The "190.00" is actually pulled from the context, but there are  
> other tests ahead of this to make sure we've got a real value there.  
> When the template is rendered, I get this error message:
>
> java.io.IOException:  
> org.apache.velocity.exception.MethodInvocationException: Invocation  
> of method 'format' in  class  
> org.apache.velocity.tools.generic.NumberTool threw exception  
> java.lang.IllegalArgumentException: Malformed pattern "#," @  
> template.vm[57,32]
> 	at ...
>
> Now what is odd about this, is that it IS a valid number format -  
> and looking at the source of the NumberTool, it looks like it would  
> just stuff those values into a DecimalFormat and be done with it. Is  
> velocity choking because of the #-pound-signs?
>
> I double checked my format with these lines:
>
> DecimalFormat f = new DecimalFormat("#,##0.##");
> System.out.println(f.format(190.00D));
>
> And this produces the result I expect: "190"
>
> Also, I do have the Locale in the context too - it's just the  
> default Locale which it looks like would be picked up automatically  
> when not specified so I've not tried this avenue.
>
> Any thoughts on this?
>
> Many thanks in advance.
>
> J --