velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan Saltz <I...@BUC.com>
Subject RE: ArrayList Failure
Date Tue, 13 Feb 2001 21:28:59 GMT

[snip]

>Take a look and see what the return type of '$query.cond' is....

Ahh, not being much of a web programmer, I forgot that radio buttons with
value "1" really return a string with value "1". So that would explain it.
Silly me. :-0

This works:
$condText.get($query.conditionAsInt)
if I convert to an Integer in the Hashtable $query in my Java code.

It sort of destroys the symmetry of not playing with the form data coming in
with the HttpRequest.getParameter, since I was just stuffing it in the
Hashmap. So that brings up the following question:

Q1) Is there a way, in the template itself, to do conversions?
For example #set ($i = $query.cond - 1) followed by $arr.get($i) doesn't
work.
Is there a  math.toInt($query.cond) tool?

Unrelated, but just as valuable to know:
Q2)
$query.conditionAsInt is an Integer object
$arr.get($query.conditionAsInt - 1) fails.
Are we supposed to be able to embed expressions in parameter lists?
#set ($i = $query.conditionAsInt - 1) followed by $arr.get($i) works in this
case, but the expression can't be dropped in as a parameter.



Here is what I was able to do just now :

My template :

#set($arr = ["a","b","c"])
#set($foo = 1)

$arr.get(1)
$arr.get($foo)
$arr.get($one)
$arr.get($provider.getInt() )
$arr.get($provider.getInteger() )
$arr.get($provider.int )
$arr.get($provider.integer)

Where in my test program :

   context.put("one", new Integer(1) );

and in the test provider (see org.apache.velocity.test.misc and environs...)

 public int getInt()
 {
  return 1;
 }

 public Integer getInteger()
 {
  return new Integer(1);
 }


my output :


b
b
b
b
b
b
b

So things seem fine.  This was done with the 20010213 nightly snapshot under
WinNT w/ jdk1.3

Take a look and see what the return type of '$query.cond' is....

geir
-------------------------------------------------------

-- 
---------------------------------
I love the man that can smile in trouble,
that can gather strength from distress,
and grow brave by reflection.
- Thomas Paine
---------------------------------

Mime
View raw message