Geir,
>From Section 15.1 User Guide:
"Designers should note that set produces strings, which must be converted to
integers to be used by the range operator. This example shows such a
conversion:
#set($a = "7")
#set($b = $int.valueOf($a) + 10)
$b
Yields the result 17. "
Just to clarify - Resource.getPrice() returns a float, not a Float.
I take it from your comment that, in the above quoted example, it is
actually the duty of the programmer to 'put' the object referred to by $int
into the VelocityContext? If so, what object would that be? (I tried
Integer, but that didn't work either.)
The log entry is:
Fri Oct 12 18:08:35 EDT 2001 [error] RHS of #set statement is null. Context
will not be modified. vrshow.html [line 19, column 8]
Line 19 is:
#set($charge = $int.valueOf($entry.elementAt(0).Price)) ##does not work
Regards,
Terry
PS: I'm sure that once I 'get' what's going on here, it will be very easy.
I assure you that when that happens I will document it very clearly for my
customers (and for you, if you want it).
----- Original Message -----
From: "Geir Magnusson Jr." <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 12, 2001 10:23 PM
Subject: Re: Continuing VTL Problems
> On 10/12/01 10:00 PM, "Terry Steichen" <[EMAIL PROTECTED]> wrote:
>
> > Geir,
> >
> > On the Java side, I have an set of Resource objects each of which has a
> > method getPrice() returning a float. (I mistakenly said it was an
Integer,
> > below.) I then populate a 'bundle' vector with one Resource object and
> > another different object. I then collect all these 'bundle' vectors
into an
> > 'rdata' vector.
> >
> > On the template side, I use $rdata to extract the the 'rdata' vector and
> > then use #foreach to remove each 'bundle' vector as $entry. The first
> > element of $entry is the Resource object ($entry.elementAt(0)); I then
use
> > $entry.elementAt(0).Price to retrieve the price. So, the actual object
is a
> > Float(), not a String().
> >
> > However, as I understand it, $entry.elementAt(0).Price returns a string.
If
> > that is correct, then $int.valueOf($entry.elementAt(0).Price) should
(??)
> > return an int (that can be used in computation).
> >
>
> If I understand you, $entry.elementAt(0) returns a Resource object.
>
> This Resource object has a method
>
> public Float getPrice()
>
> Therefore $entry.elementAt(0).price will result in a Float, not a String.
>
> Velocity does no type casting or transformation. If .price returns a
Float,
> a Float it will be.
>
> What's in the log? :)
>
> > But it doesn't work. I'm sure I'm missing something, probably very
obvious.
> > But I don't know what it is.
>
> I think it's this.
>
> > Regards,
> >
> > Terry
> >
> > PS: I'm assuming that $int is a built-in Integer object (available in
the
> > VelocityContext, per the documentation)? If that's not so (meaning it's
not
> > built-in and I have to insert it), perhaps that's my problem?
>
> That's one of them. :)
>
> There are *no* built-in objects in the context, and no reserved keys.
>
> Where in the docs did you find that?
>
> geir
>
> >
> > ----- Original Message -----
> > From: "Geir Magnusson Jr." <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Friday, October 12, 2001 9:14 PM
> > Subject: Re: Continuing VTL Problems
> >
> >
> >> On 10/12/01 8:18 PM, "Terry Steichen" <[EMAIL PROTECTED]> wrote:
> >>
> >>> I'm still having some problems with converting variables to integers
so
> > I can
> >>> perform operations on/with them. (I've got some complex displays.)
In
> > this
> >>> particular case, my Java code is doing a context.put() of a vector of
> > vectors,
> >>> each of which holds several objects, one of which is an Integer
object.
> > The
> >>> reference (at the VTL level, inside the #foreach($entry in $entries)
> >>> directive) is $entry.elementAt(0).Price. It displays fine, but if I
try
> > to do
> >>> any operations on it (adding, multiplying, etc.), the result is
(apparen
> > tly)
> >>> null. I've tried $int.valueOf($entry.elementAt(0).Price), but that
has
> > the
> >>> same outcome. I've gone over both the user and dev docs again and
find
> > only a
> >>> mention that you must use integers.
> >>>
> >>> In other words, in the template:
> >>>
> >>> #set($charge = 1 * $int.valueOf($entry.elementAt(0).Price)) does *not*
> > work.
> >>> #set($charge = $int.valueOf($entry.elementAt(0).Price)) does *not*
work
> >>> #set($charge = $entry.elementAt(0).Price) works, in the sense that
it's
> > value
> >>> is not null.
> >>>
> >>
> >> I am going to assume that $entry.elementAt(0).Price is supposed to be a
> >> java.lang.String and $int is a java.lang.Integer.
> >>
> >> I suspect that Price isn't, as the line
> >>
> >> #set($charge = $int.valueOf($entry.elementAt(0).Price))
> >>
> >> Appears at first glance to be perfectly valid.
> >>
> >> What does the velocity.log say - there should be something in there...
> >>
> >>> Please give me some idea of how to handle this stuff without
introducing
> > too
> >>> much logic into the template and I'll be happy to write it up for
> > others.
> >>
> >> I don't think that's the issue...
> >>
> >>> Regards,
> >>>
> >>> Terry
> >>>
> >>> PS: Someone suggested my earlier question would better fit into the
> > users'
> >>> (rather than developers') group. I'm staying with the developer's
list
> >>> because these questions seem to be deeper than template editing (but
> >>> admittedly more specific and pragmatic than deep 'inner guts' stuff).
> >>>
> >>
> >> So far, this is perfectly acceptable stuff for -user.
> >>
> >> Geir
> >>
> >> --
> >> Geir Magnusson Jr. [EMAIL PROTECTED]
> >> System and Software Consulting
> >> "Whoever would overthrow the liberty of a nation must begin by subduing
> > the
> >> freeness of speech." - Benjamin Franklin
> >>
> >>
> >>
> >
>
> --
> Geir Magnusson Jr. [EMAIL PROTECTED]
> System and Software Consulting
> "They that can give up essential liberty to obtain a little temporary
safety
> deserve neither liberty nor safety." - Benjamin Franklin
>
>
>