velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nat...@esha.com>
Subject Re: calling setProperty(float) not possible ?
Date Wed, 11 Jul 2001 17:24:28 GMT
if you can't alter the methods you are trying to call, then you will
probably need to put an object in the context as a tool for converting the
number to a java float.  this is untested and off the top of my head, but
something like...

public class NumberConverter {

    public NumberConverter {}

    public static float toFloatPrimitive(int number) {
        return (float) number;
    }
}

then put one in the context and use like this

$person.setIncome($numconv.toFloatPrimitive(5000))

i haven't tested this, but something like it should work for you.

-nathan


----- Original Message -----
From: "Thomas Fahrmeyer" <thomas.fahrmeyer@einsurance.de>
To: "Velocity-User" <velocity-user@jakarta.apache.org>
Sent: Wednesday, July 11, 2001 8:02 AM
Subject: calling setProperty(float) not possible ?


> Hi,
>
> I have an object called "person" with method "setIncome(float income)"
> accessible within the template:
> ...
> $person.setIncome(5000)
> ...
>
> while merging the template Vel don't calls setIncome, because the 5000 is
> interpreted as an int and a method with that signature doesnt exist. Okay,
> but if I try
> $person.setIncome(5000f)
>
> to force to interpret the argument as float - Velocity comes up with an
> error:
> Wed Jul 11 16:53:54 GMT+02:00 2001  [error] Parser Exception: list.htm :
> org.apache.velocity.runtime.parser.ParseException: Encountered "f" at line
> 35, column 31.
> Was expecting one of:
>     "," ...
>     ")" ...
>     <WHITESPACE> ...
>
> at org.apache.velocity.runtime.parser.Parser.process(Parser.java:190)
> at org.apache.velocity.runtime.parser.Parser.parse(Parser.java:78)
> at org.apache.velocity.runtime.Runtime.parse(Runtime.java:620)
> at org.apache.velocity.Template.process(Template.java:159)
> at
>
org.apache.velocity.runtime.resource.ResourceManager.getResource(ResourceMan
> ager.java:336)
> at org.apache.velocity.runtime.Runtime.getTemplate(Runtime.java:667)
> at
>
org.apache.velocity.servlet.VelocityServlet.getTemplate(VelocityServlet.java
> :489)
> at
>
de.einsurance.gui.framework.AbstractScreen.handleRequest(AbstractScreen.java
> :171)
> at
>
de.einsurance.gui.framework.TemplateScreen.handleRequest(TemplateScreen.java
> :52)
> at
>
org.apache.velocity.servlet.VelocityServlet.doRequest(VelocityServlet.java:3
> 26)
> ...
>
> How can I handle methods needing floats, doubles or other datatypes as
> arguments ?? I would not be easy to used Float or Double Objects (if that
> would be the solution) ;( Here generated objects are used.
>
> Thanx.
> Thomas
>
>


Mime
View raw message